Update the rest of Either to match
This commit is contained in:
parent
ebc3f07610
commit
f432f7796c
@ -3,26 +3,26 @@ export type Right<A> = {readonly _tag: 'Right', readonly right: A}
|
|||||||
export type Either<A, E> = Right<A> | Left<E>
|
export type Either<A, E> = Right<A> | Left<E>
|
||||||
|
|
||||||
// Constructors
|
// Constructors
|
||||||
export const left = <E>(e: E): Either<E, never> => ({
|
export const left = <E>(e: E): Either<never, E> => ({
|
||||||
_tag: 'Left',
|
_tag: 'Left',
|
||||||
left: e,
|
left: e,
|
||||||
})
|
})
|
||||||
export const right = <A>(a: A): Either<never, A> => ({
|
export const right = <A>(a: A): Either<A, never> => ({
|
||||||
_tag: 'Right',
|
_tag: 'Right',
|
||||||
right: a,
|
right: a,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Operations
|
// Operations
|
||||||
export const eitherMap =
|
export const eitherMap =
|
||||||
<E, A, B>(f: (a: A) => B) => (fa: Either<E, A>): Either<E, B> =>
|
<E, A, B>(f: (a: A) => B) => (fa: Either<A, E>): Either<B, E> =>
|
||||||
fa._tag === 'Right' ? right(f(fa.right)) : fa
|
fa._tag === 'Right' ? right(f(fa.right)) : fa
|
||||||
|
|
||||||
export const eitherChain =
|
export const eitherChain =
|
||||||
<E, A, B>(f: (a: A) => Either<E, B>) =>
|
<E, A, B>(f: (a: A) => Either<B, E>) =>
|
||||||
(fa: Either<E, A>): Either<E, B> =>
|
(fa: Either<A, E>): Either<B, E> =>
|
||||||
fa._tag === 'Right' ? f(fa.right) : fa
|
fa._tag === 'Right' ? f(fa.right) : fa
|
||||||
|
|
||||||
export const fold =
|
export const fold =
|
||||||
<E, A, B>(onLeft: (e: E) => B, onRight: (a: A) => B) =>
|
<A, B, E>(onLeft: (e: E) => B, onRight: (a: A) => B) =>
|
||||||
(fa: Either<E, A>): B =>
|
(fa: Either<A, E>): B =>
|
||||||
fa._tag === 'Left' ? onLeft(fa.left) : onRight(fa.right)
|
fa._tag === 'Left' ? onLeft(fa.left) : onRight(fa.right)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user