我可以问一个是否它是左(或右)? [英] Can I ask an Either whether it is Left (or Right)?
问题描述
isLeft = either(const True)(const False)
isRight =或者(const False)(const True)
在标准库中有类似的东西吗?
虽然这已经很老了,但在这里发布供参考。
现在位于 Data.
之后的标准库中,因为4.7:
https://hackage.haskell.org/package/base-4.7 .0.0 / docs / Data-Either.html
isLeft ::或者ab - > Bool
如果给定值是一个Left值,则返回True,否则返回False。
isRight ::或者ab - > Bool
如果给定的值是一个Right值,则返回True,否则返回False。
I know I can usually just pattern match, but sometimes I would find these functions useful:
isLeft = either (const True) (const False)
isRight = either (const False) (const True)
Is there something like that in the standard library?
While this is pretty old, posting here for reference.
This is now in the standard library under Data.Either
since 4.7:
https://hackage.haskell.org/package/base-4.7.0.0/docs/Data-Either.html
isLeft :: Either a b -> Bool
Return True if the given value is a Left-value, False otherwise.
isRight :: Either a b -> Bool
Return True if the given value is a Right-value, False otherwise.
这篇关于我可以问一个是否它是左(或右)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!