aboutsummaryrefslogtreecommitdiff
path: root/src/either.js
blob: 75b3c4cffdf064516fe2617acf5a748a21e115d1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import * as wrapper from "./wrapper.js"

export const Left  = v => left => right => left(v)
export const Right = v => left => right => right(v)

export const isLeft  = either => either(true)(_ => false)
export const isRight = either => either(false)(_ => true)

export const getLeft  = left  => left(v => v)()
export const getRight = right => right()(v => v)

export const show = either => either(v => "Left " + v)(v => "Right " + v)

export const unit = Right
export const bind = mx => f => mx(Left)(f)

export const DO = wrapper.DO(unit, bind)