Skip to content

Commit

Permalink
Add few more drain implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
phadej committed Nov 10, 2023
1 parent 81a1967 commit 91b6b72
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions witherable/src/Witherable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ instance Witherable Maybe where

instance Filterable Option where
mapMaybe f = (>>= Option . f)
drain _ = Option Nothing
{-# INLINE mapMaybe #-}

instance Witherable Option where
Expand All @@ -207,6 +208,9 @@ instance Monoid e => Filterable (Either e) where
mapMaybe f (Right a) = maybe (Left mempty) Right $ f a
{-# INLINABLE mapMaybe #-}

drain (Left e) = Left e
drain (Right _) = Left mempty

instance Monoid e => Witherable (Either e) where
wither _ (Left e) = pure (Left e)
wither f (Right a) = fmap (maybe (Left mempty) Right) (f a)
Expand Down

0 comments on commit 91b6b72

Please sign in to comment.