[英]Using # with Either types in PureScript
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
: 但是,我想用
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. 应该为每个函数解包一个
Right
值,而Left
值应该简单地传递不变。 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 . 您正在寻找
<#>
,它是Functor的mapFlipped的运算符别名。 The Functor instance for Either
applies a function to the content of Right
, but leaves Left
values untouched. Either
的Functor实例将一个函数应用于Right
的内容,但Left
值保持不变。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.