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

Bifoldable #94

Closed
ceedubs opened this issue Feb 6, 2015 · 8 comments
Closed

Bifoldable #94

ceedubs opened this issue Feb 6, 2015 · 8 comments

Comments

@ceedubs
Copy link
Contributor

ceedubs commented Feb 6, 2015

Bifoldable is a type class (currently not in cats) for a type that has two separate Foldables. For example, Or has a Foldable instance (via its Traverse instance) that folds over the RightOr case, but Or could equally fold over the LeftOr case.

One of my favorite methods from scalaz is MonadPlus.separate. This can do things like take a List[A Or B] and turn it into a (List[A], List[B]). Or similarly, take a List[(A, B)] and turn it into a (List[A], List[B]). In Cats, I believe we could implement the same sort of method on MonadFilter if we were to bring in a Bifoldable type class.

What do people think? Is this something that would belong in core?

@tpolecat
Copy link
Member

tpolecat commented Feb 6, 2015

Yep, I would like to see Bifoldable.

@mpilquist
Copy link
Member

It's worth mentioning that Foldable and Bifoldable are lawless. We admitted Foldable anyway due to its usefulness for adhoc polymorphism. Bifoldable occurs much less frequently in practice, so we might want to carefully consider its inclusion.

@adelbertc
Copy link
Contributor

@mpilquist
Copy link
Member

Those only require that foldMap, foldLeft, and foldRight are mutually consistent. They only exist in Scalaz because Foldable can be implemented in terms of foldMap or foldRight. If you pick one as the abstract method and just derive the other, the law simplifies to a unit test of the derived method.

@non
Copy link
Contributor

non commented May 22, 2015

Is there consensus here?

So far it seems like @ceedubs and @tpolecat would like to see this and @mpilquist is skeptical?

@coltfred
Copy link
Contributor

coltfred commented Nov 6, 2015

I personally use Bifoldable from Scalaz on a regular basis and would like to have it.

Plus it gives rise to wildly useful things like separate on MonadPlus.

👍

@mpilquist
Copy link
Member

Re-reading this just now, I'm not skeptical of adding Bifoldable. 👍

adelbertc added a commit to adelbertc/cats that referenced this issue Feb 5, 2016
Also:
- Add MonadCombine separate
- Add serializability check for Bifunctor[Xor]
mpilquist added a commit that referenced this issue Feb 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants