Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I collapse an Either in PureScript?

I have an object of type Either String (Either String Int). I would like to collapse it to an object of type Either String Int.

Is there a provided function for this in PureScript?

like image 891
sdgfsdh Avatar asked Dec 24 '16 19:12

sdgfsdh


1 Answers

It is the same as 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
like image 190
sdgfsdh Avatar answered Nov 04 '22 08:11

sdgfsdh