Skip to content

Add part(ition) and part(ition)ing to Filterable #45

@Jashweii

Description

@Jashweii

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 b

The 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions