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 for Either
applies a function to the content of Right
, but leaves Left
values untouched.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.