import { match, left, right } from 'fp-ts/Either'
import { pipe } from 'fp-ts/function'
function onLeft(errors: Array<string>): string {
return `Errors: ${errors.join(', ')}`
}
function onRight(value: number): string {
return `Ok: ${value}`
}
assert.strictEqual(
pipe(
right(1),
match(onLeft, onRight)
),
'Ok: 1'
)
assert.strictEqual(
pipe(
left(['error 1', 'error 2']),
match(onLeft, onRight)
),
'Errors: error 1, error 2'
)
2.10.0
Takes two functions and an
Either
value, if the value is aLeft
the inner value is applied to the first function, if the value is aRight
the inner value is applied to the second function.