如何在PureScript中折叠Either?

时间:2016-12-24 19:01:31

标签: purescript either

我有Either String (Either String Int)类型的对象。我想将它折叠为Either String Int类型的对象。

PureScript中是否提供了此功能?

1 个答案:

答案 0 :(得分:4)

与Haskell相同:

import Prelude
import Data.Either

let a = Left "a" :: Either String (Either String Int)
let b = Right (Left "b") :: Either String (Either String Int)
let c = Right (Right 123) :: Either String (Either String Int)

join a -- Left "a"
join b -- Left "b"
join c -- Right 123