@sweet-monads/either
Advanced tools
Comparing version
@@ -19,2 +19,3 @@ import { Monad } from "@sweet-monads/interfaces"; | ||
static merge<L1, R1, L2, R2, L3, R3, L4, R4, L5, R5, L6, R6, L7, R7, L8, R8, L9, R9, L10, R10>(values: [Either<L1, R1>, Either<L2, R2>, Either<L3, R3>, Either<L4, R4>, Either<L5, R5>, Either<L6, R6>, Either<L7, R7>, Either<L8, R8>, Either<L9, R9>, Either<L10, R10>]): Either<L1 | L2 | L3 | L4 | L5 | L6 | L7 | L8 | L9 | L10, [R1, R2, R3, R4, R5, R6, R7, R8, R9, R10]>; | ||
static from<T>(v: T): Either<{}, T>; | ||
static right<L, T>(v: T): Either<L, T>; | ||
@@ -26,7 +27,10 @@ static left<T, R>(v: T): Either<T, R>; | ||
isRight(): boolean; | ||
join<L1, L2, R>(this: Either<L1, Either<L2, R>>): Either<L1 | L2, R>; | ||
mapRight<T>(f: (r: R) => T): Either<L, T>; | ||
mapLeft<T>(f: (l: L) => T): Either<T, R>; | ||
map<T>(f: (r: R) => T): Either<L, T>; | ||
asyncMap<T>(f: (r: R) => Promise<T>): Promise<Either<L, T>>; | ||
chain<A, B>(f: (r: R) => Either<A, B>): Either<A | L, B>; | ||
asyncChain<A, B>(f: (r: R) => Promise<Either<A, B>>): Promise<Either<A | L, B>>; | ||
} | ||
export {}; |
18
index.js
@@ -13,2 +13,5 @@ const EitherType = { | ||
} | ||
static from(v) { | ||
return this.right(v); | ||
} | ||
static right(v) { | ||
@@ -26,2 +29,5 @@ return new Either(EitherType.Right, v); | ||
} | ||
join() { | ||
return this.chain(x => x); | ||
} | ||
mapRight(f) { | ||
@@ -42,2 +48,8 @@ return this.map(f); | ||
} | ||
asyncMap(f) { | ||
if (this.isLeft()) { | ||
return Promise.resolve(Either.left(this.value)); | ||
} | ||
return f(this.value).then(v => Either.right(v)); | ||
} | ||
chain(f) { | ||
@@ -49,2 +61,8 @@ if (this.isLeft()) { | ||
} | ||
asyncChain(f) { | ||
if (this.isLeft()) { | ||
return Promise.resolve(Either.left(this.value)); | ||
} | ||
return f(this.value); | ||
} | ||
} |
{ | ||
"name": "@sweet-monads/either", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Either monad", | ||
@@ -14,3 +14,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"@sweet-monads/interfaces": "^1.0.0" | ||
"@sweet-monads/interfaces": "^1.1.0" | ||
}, | ||
@@ -17,0 +17,0 @@ "author": "", |
12912
5.84%100
28.21%