-
Notifications
You must be signed in to change notification settings - Fork 31
Open
Description
Addressing #21
class Functor f => Filterable f where
...
part :: f (Either a b) -> (f a, f b)
part = parting id
parting :: (c -> Either a b) -> f c -> (f a, f b)
parting f fc = (mapMaybe (isLeft . f) fc, mapMaybe (isRight . f) fc)
-- default implementation in terms of mapMaybe where (definitions omitted)
-- isLeft :: Either a b -> Maybe a
-- isRight :: Either a b -> Maybe bThe default implementation uses mapMaybe twice (mapMaybe and parting can both be expressed in terms of the other). By adding it as a method, lists, maps and other instances can avoid making two traversals.
Likewise indexed and applicative/traversal variants could be added.
hseg and Ericson2314spacekitteh
Metadata
Metadata
Assignees
Labels
No labels