aboutsummaryrefslogtreecommitdiff
path: root/src/either.js
blob: 5bc4ab69ed5e4807cc3ee49f8da02b7d773b6a68 (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)