packages feed

witherable 0.1.3 → 0.1.3.1

raw patch · 2 files changed

+15/−26 lines, 2 files

Files

src/Data/Witherable.hs view
@@ -126,7 +126,7 @@   {-# INLINE mapMaybe #-}    catMaybes :: t (Maybe a) -> t a-  catMaybes = catMaybesOf wither+  catMaybes = mapMaybe id   {-# INLINE catMaybes #-}    filterA :: Applicative f => (a -> f Bool) -> t a -> f (t a)@@ -150,23 +150,21 @@  -- | Remove the duplicate elements through a filter. ordNubOf :: Ord a => FilterLike' (State (Set.Set a)) s a -> s -> s-ordNubOf w t = evalState (filterAOf w f t) Set.empty+ordNubOf w t = evalState (w f t) Set.empty   where-    f a = state $ \s ->-      case Set.member a s of-        True  -> (False, s)-        False -> (True, Set.insert a s)+    f a = state $ \s -> if Set.member a s+      then (Nothing, s)+      else (Just a, Set.insert a s) {-# INLINE ordNubOf #-}  -- | Remove the duplicate elements through a filter. -- It is often faster than 'ordNubOf', especially when the comparison is expensive. hashNubOf :: (Eq a, Hashable a) => FilterLike' (State (HSet.HashSet a)) s a -> s -> s-hashNubOf w t = evalState (filterAOf w f t) HSet.empty+hashNubOf w t = evalState (w f t) HSet.empty   where-    f a = state $ \s ->-      case HSet.member a s of-        True  -> (False, s)-        False -> (True, HSet.insert a s)+    f a = state $ \s -> if HSet.member a s+      then (Nothing, s)+      else (Just a, HSet.insert a s) {-# INLINE hashNubOf #-}  -- | Removes duplicate elements from a list, keeping only the first@@ -195,34 +193,27 @@   {-# INLINABLE wither #-}  instance Witherable [] where-  wither f = go where-    go (x:xs) = maybe id (:) <$> f x <*> go xs-    go [] = pure []-  {-# INLINE wither #-}+  wither f = build w where+    w c n = go where+      go (x:xs) = maybe id c <$> f x <*> go xs+      go [] = pure n+  {-# INLINE[0] wither #-}   mapMaybe = Maybe.mapMaybe-  {-# INLINE mapMaybe #-}   catMaybes = Maybe.catMaybes-  {-# INLINE catMaybes #-}   filter = Prelude.filter-  {-# INLINE filter #-}  instance Witherable IM.IntMap where   mapMaybe = IM.mapMaybe-  {-# INLINE mapMaybe #-}   filter = IM.filter-  {-# INLINE filter #-}  instance Ord k => Witherable (M.Map k) where   mapMaybe = M.mapMaybe-  {-# INLINE mapMaybe #-}   filter = M.filter-  {-# INLINE filter #-}  instance (Eq k, Hashable k) => Witherable (HM.HashMap k) where   wither f = fmap HM.fromList . wither (\(i, a) -> fmap ((,) i) <$> f a) . HM.toList   {-# INLINABLE wither #-}   filter = HM.filter-  {-# INLINE filter #-}  #if (MIN_VERSION_base(4,7,0)) instance Witherable Proxy where@@ -237,13 +228,11 @@   wither f = fmap V.fromList . wither f . V.toList   {-# INLINABLE wither #-}   filter = V.filter-  {-# INLINE filter #-}  instance Witherable S.Seq where   wither f = fmap S.fromList . wither f . F.toList   {-# INLINABLE wither #-}   filter = S.filter-  {-# INLINE filter #-}  -- | Traversable containers which hold 'Maybe' are witherable. newtype Chipped t a = Chipped { getChipped :: t (Maybe a) } deriving (Functor, F.Foldable, T.Traversable)
witherable.cabal view
@@ -1,5 +1,5 @@ name:                witherable-version:             0.1.3+version:             0.1.3.1 synopsis:            Generalization of filter and catMaybes -- description: homepage:            https://github.com/fumieval/witherable