@sweet-monads/either
Advanced tools
Comparing version 1.2.1 to 1.2.2
22
index.js
const EitherType = { | ||
Left: "Left", | ||
Right: "Right", | ||
Right: "Right" | ||
}; | ||
@@ -8,3 +8,3 @@ function isWrappedFunction(m) { | ||
} | ||
exports.Either = class Either { | ||
class Either { | ||
constructor(type, value) { | ||
@@ -14,5 +14,19 @@ this.type = type; | ||
} | ||
static merge(eithers) { | ||
static mergeInOne(eithers) { | ||
return eithers.reduce((res, v) => v.chain(v => res.map(res => res.concat([v]))), Either.right([])); | ||
} | ||
static mergeInMany(eithers) { | ||
return eithers.reduce((res, v) => { | ||
if (res.isLeft()) { | ||
if (v.isLeft()) { | ||
return Either.left(res.value.concat([v.value])); | ||
} | ||
return res; | ||
} | ||
if (v.isLeft()) { | ||
return Either.left([v.value]); | ||
} | ||
return v.chain(v => res.map(res => res.concat([v]))); | ||
}, Either.right([])); | ||
} | ||
static from(v) { | ||
@@ -88,1 +102,3 @@ return this.right(v); | ||
} | ||
Either.merge = Either.mergeInOne; | ||
module.exports = Either; |
@@ -14,3 +14,3 @@ import { Monad } from "@sweet-monads/interfaces"; | ||
export class Either<L, R> implements Monad<R> { | ||
export default class Either<L, R> implements Monad<R> { | ||
static mergeInOne<L1, R1>(values: [Either<L1, R1>]): Either<L1, [R1]>; | ||
@@ -17,0 +17,0 @@ static mergeInOne<L1, R1, L2, R2>( |
{ | ||
"name": "@sweet-monads/either", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Either monad", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -22,3 +22,3 @@ # @sweet-monads/either | ||
```typescript | ||
import { Either } from "@sweet-monads/either"; | ||
import Either from "@sweet-monads/either"; | ||
@@ -25,0 +25,0 @@ class UserNotFoundError extends Error { name: "UserNotFoundError" }; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
32404
6
577
0