Using # with Either types in PureScript

110 views Asked by At

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?

1

There are 1 answers

0
stholzm On BEST ANSWER

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.