-
Notifications
You must be signed in to change notification settings - Fork 69
Add combinators to transform type of Ring, Group, Eq, etc #116
Comments
Sounds like we need a Bijection. :) We added something like this to Bijection actually: https://github.com/twitter/bijection/pull/183/files which let's you generalize this imap idea. Also, it algebird we added bijected algebras: Here, Eq.on is the same as contramap. As is Order.on. About imap, see #108. That one, which I think should probably rarely be used (at Twitter, bijected algebras are pretty rare actually. One benefit of the bijected algebra is that you can leverage combineAll to not apply the bijection too much, but the naive approach of applying both functions on each combine to combine a big list is costly). I'd probably not add imap, and instead make a class similar to BijectedRing to handle this. |
In Cats I originally had a bijection type but realized I didn't want to step on twitter/bijection's toes, so we removed it. I agree that it's a lot cleaner. I think the "bijected algebra" (or "mapped algebra") approach makes a lot of sense for the reasons you mention. I could imagine a similar argument being used in favor of putting concrete sorting implementations on |
It could also be contramap[A, B](ra: Ring[A])(f: Iso[B, A]): Ring[B] but I guess folks don't want to pull in a lens library. EDIT: I corrected |
@johnynek Ah - that looks delightful. If we had these methods existing on the type classes already, then it would make the implementation of a |
For types like
Ring
, we should include animap(f: A => B, g: B => A): Ring[B]
method for transforming the type class. This also includecontramap(f: B => A)
on type classes likeEq
andOrder
.The text was updated successfully, but these errors were encountered: