5

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?

sdgfsdh
  • 33,689
  • 26
  • 132
  • 245
  • I don't know purescript, but this is `join` (with `Either String` as the monad) in Haskell. Maybe that helps? – luqui Dec 24 '16 at 19:28
  • @luqui yes, it is more-or-less the same as Haskell – sdgfsdh Dec 24 '16 at 19:32
  • 3
    @sdgfsdh Just a tip, purescript's typed holes can search for definitions that match their type: check out http://try.purescript.org/?gist=7552f9f7edeae7f58e5114c9a479fb53&backend=core as an example – Christoph Hegemann Dec 25 '16 at 12:26

1 Answers1

6

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
sdgfsdh
  • 33,689
  • 26
  • 132
  • 245
  • Consider accepting this answer so the question shows up as answered. –  Jan 01 '17 at 00:13