Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compactable, Filterable, Witherable #268

Open
andywhite37 opened this issue May 5, 2020 · 0 comments
Open

Compactable, Filterable, Witherable #268

andywhite37 opened this issue May 5, 2020 · 0 comments

Comments

@andywhite37
Copy link
Member

andywhite37 commented May 5, 2020

It would be cool 😎 to add a few more typeclasses to the mix: Compactable, Filterable, and Witherable. These are all related to compacting/filtering/partitioning data structures. We already have some of these functions for certain types, so this would just be to formalize the abstractions, even though abstractions are not always super easy to use in Reason.

https://github.com/LiamGoodacre/purescript-filterable

class Compactable f where
  compact :: forall a.
    f (Maybe a) -> f a

  separate :: forall l r.
    f (Either l r) -> { left :: f l, right :: f r }
class (Compactable f, Functor f) <= Filterable f where
  partitionMap :: forall a l r.
    (a -> Either l r) -> f a -> { left :: f l, right :: f r }

  partition :: forall a.
    (a -> Boolean) -> f a -> { no :: f a, yes :: f a }

  filterMap :: forall a b.
    (a -> Maybe b) -> f a -> f b

  filter :: forall a.
    (a -> Boolean) -> f a -> f a
class (Filterable t, Traversable t) <= Witherable t where
  wilt :: forall m a l r. Applicative m =>
    (a -> m (Either l r)) -> t a -> m { left :: t l, right :: t r }

  wither :: forall m a b. Applicative m =>
    (a -> m (Maybe b)) -> t a -> m (t b)
@andywhite37 andywhite37 changed the title Compactalbe, Filterable, Witherable Compactable, Filterable, Witherable May 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant