I like to use #
to pass a value through several functions since it makes for more readable code:
1 # (\n -> n * 2) # (\n -> n + 1)
However, I would like do this with an Either
:
(Right 1) ??? (\n -> n * 2) ??? (\n -> n + 1)
A Right
value should be unpacked for each function, whereas a Left
value should simply get passed through unchanged. In other words:
(Right x) ??? f == Right f(x)
(Left x) ??? f == Left x
Is there already an operator for this?
You are looking for
<#>
which is an operator alias for Functor's mapFlipped. The Functor instance forEither
applies a function to the content ofRight
, but leavesLeft
values untouched.