@sweet-monads/either
Advanced tools
Comparing version 3.2.0 to 3.3.0
{ | ||
"name": "@sweet-monads/either", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"description": "Either monad", | ||
@@ -32,3 +32,3 @@ "main": "./cjs/index.js", | ||
"dependencies": { | ||
"@sweet-monads/interfaces": "^3.2.0" | ||
"@sweet-monads/interfaces": "^3.3.0" | ||
}, | ||
@@ -35,0 +35,0 @@ "author": "JSMonk", |
@@ -61,2 +61,3 @@ # @sweet-monads/either | ||
- [`Either#asyncChain`](#eitherasyncchain) | ||
- [`Either#fold`](#eitherfold) | ||
- [Helpers](#helpers) | ||
@@ -501,2 +502,21 @@ | ||
##### `Either#fold` | ||
```typescript | ||
function fold<C>(mapLeft: (value: L) => C, mapRight: (value: R) => C): C; | ||
``` | ||
- Returns values mapped by `mapRight` if `Either` is `Right`, otherwise value mapped by `mapLeft` | ||
Example: | ||
```typescript | ||
const v1 = right<Error, number>(2); | ||
const v2 = left<Error, number>(new Error()); | ||
// 4 | ||
const newVal1 = v1.fold(() => 'fail', value => value * 2); | ||
// "fail" | ||
const newVal2 = v2.fold(() => 'fail', value => value * 2); | ||
``` | ||
#### Helpers | ||
@@ -516,3 +536,3 @@ | ||
right(2).unwrap((; // number | ||
right(2).unwrap(); // number | ||
left(new TypeError()).unwrap(x => x); // throws TypeError provied in arguments | ||
@@ -519,0 +539,0 @@ |
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
547
33005
4
313
1