You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was wondering what the maintainers think about adding something like Haskell's Control.Applicative.Backwards and Data.Functor.Reverse to cats.
Or maybe something like this already exists in cats and I missed it.
Backwards
Backwards is a newtype wrapper around any f a.
If that f has an instance for Applicative, then so does Backwards f.
With good ol' applicative composition, this code will print "1" and "2", in that order.
dataTest=TestIntStringderivingShowlet x =doputStrLn"1"; pure1::IOIntlet y =doputStrLn"2"; pure"2"::IOStringTest<$> x <*> y
But by wrapping the effects in Backwards, "2" is printed before "1":
forwards $Test<$>Backwards x <*>Backwards y
Reverse
Reverse is a newtype wrapper around any f a.
If that f has an instance for Foldable, then so does Reverse f.
If that f has an instance for Traversable, then so does Reverse f.
Good ol' traversal will apply the effects to each element of a list, going left to right:
λ>traverseprint [1,2,3]
123
But by wrapping the f a in Reverse, the effects of the traversal are observed in right to left fashion.
traverseprint (Reverse [1,2,3])
321
If this is deemed a good fit for cats, I wouldn't mind giving it a go.
The text was updated successfully, but these errors were encountered:
We have newts for these kinds of things. But maybe with #1800 and opaque types on the horizon, it might make sense to rethink the separation and consider moving them into the cats repo. :)
I was wondering what the maintainers think about adding something like Haskell's
Control.Applicative.Backwards
andData.Functor.Reverse
to cats.Or maybe something like this already exists in cats and I missed it.
Backwards
Backwards
is a newtype wrapper around anyf a
.If that
f
has an instance forApplicative
, then so doesBackwards f
.With good ol' applicative composition, this code will print "1" and "2", in that order.
But by wrapping the effects in
Backwards
, "2" is printed before "1":Reverse
Reverse
is a newtype wrapper around anyf a
.If that
f
has an instance forFoldable
, then so doesReverse f
.If that
f
has an instance forTraversable
, then so doesReverse f
.Good ol' traversal will apply the effects to each element of a list, going left to right:
But by wrapping the
f a
inReverse
, the effects of the traversal are observed in right to left fashion.If this is deemed a good fit for cats, I wouldn't mind giving it a go.
The text was updated successfully, but these errors were encountered: