Just returns value
from Right
or Left
import { Either } from 'monad-maniac'
const left = Either.left<number, number>(300)
const right = Either.right<number, number>(150)
const resultLeft = left.get() // 300
const resultRight = right.get() // 150
Returns true
if it's Left
and false
otherwise.
import { Either } from 'monad-maniac'
const left = Either.left<number, number>(300)
const right = Either.right<number, number>(150)
const resultLeft = left.isLeft() // true
const resultRight = right.isLeft() // false
Returns false
if it's Left
and true
otherwise.
import { Either } from 'monad-maniac'
const left = Either.left<number, number>(300)
const right = Either.right<number, number>(150)
const resultLeft = left.isRight() // false
const resultRight = right.isRight() // true
Converting Either
to Maybe
.
If value in Left
will returns Nothing
, else
returns result Maybe.of
for value from Right
.
import { Either } from 'monad-maniac'
const left = Either.left<string, number>('Some Error')
const right = Either.right<string, number>(150)
const rightVoid = Either.right<string, number | void>(undefined)
const resultLeft = left.toMaybe() // Nothing()
const resultRight = right.toMaybe() // Just(150)
const resultRightVoid = rightVoid.toMaybe() // Nothing()
Returns Left
or Right
as string
: Left(left value)
or Right(right value)
.
import { Either } from 'monad-maniac'
const left = Either.left<number, number>(300)
const right = Either.right<number, number>(150)
const resultLeft = left.toString() // Left(300)
const resultRight = right.toString() // Right(150)
Generated using TypeDoc
Returns
false
if it'sLeft
andtrue
otherwise.