Compare commits
3 Commits
e897ca7848
...
f432f7796c
| Author | SHA1 | Date | |
|---|---|---|---|
| f432f7796c | |||
| ebc3f07610 | |||
| 773fcc7ef3 |
@ -7,7 +7,7 @@
|
|||||||
"quoteStyle": "alwaysSingle",
|
"quoteStyle": "alwaysSingle",
|
||||||
"trailingCommas": "onlyMultiLine",
|
"trailingCommas": "onlyMultiLine",
|
||||||
"operatorPosition": "nextLine",
|
"operatorPosition": "nextLine",
|
||||||
"arrowFunction.useParentheses": "preferNone",
|
"arrowFunction.useParentheses": "maintain",
|
||||||
"binaryExpression.linePerExpression": false,
|
"binaryExpression.linePerExpression": false,
|
||||||
"memberExpression.linePerExpression": false,
|
"memberExpression.linePerExpression": false,
|
||||||
"bracePosition": "sameLineUnlessHanging",
|
"bracePosition": "sameLineUnlessHanging",
|
||||||
|
|||||||
@ -1,28 +1,28 @@
|
|||||||
export type Left<E> = {readonly _tag: 'Left', readonly left: E}
|
export type Left<E> = {readonly _tag: 'Left', readonly left: E}
|
||||||
export type Right<A> = {readonly _tag: 'Right', readonly right: A}
|
export type Right<A> = {readonly _tag: 'Right', readonly right: A}
|
||||||
export type Either<E, A> = Left<E> | Right<A>
|
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