@sweet-monads/maybe
Advanced tools
Comparing version 3.2.0 to 3.3.0
{ | ||
"name": "@sweet-monads/maybe", | ||
"version": "3.2.0", | ||
"version": "3.3.0", | ||
"description": "", | ||
@@ -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": "", |
@@ -54,2 +54,3 @@ # @sweet-monads/maybe | ||
- [`Maybe#asyncChain`](#maybeasyncchain) | ||
- [`Maybe#fold`](#maybefold) | ||
- [Helpers](#helpers) | ||
@@ -147,3 +148,3 @@ | ||
```typescript | ||
function fromNullable<T>(value: T): Maybe<Exclude<T, null | undefined>>; | ||
function fromNullable<T>(value: T): Maybe<NonNullable<T>>; | ||
``` | ||
@@ -270,2 +271,38 @@ | ||
#### `Maybe#mapNullable` | ||
```typescript | ||
function mapNullable<Val, NewVal>(fn: (val: Val) => (NewVal | null | undefined)): Maybe<NonNullable<NewVal>>; | ||
``` | ||
- Returns mapped by `fn` function value wrapped by `Maybe` if `Maybe` is `Just` and the returned value is not `null` or `undefined` otherwise `None` | ||
Example: | ||
```typescript | ||
const v1 = just(2); | ||
const v2 = none<number>(); | ||
const newVal1 = v1.mapNullable(a => a.toString()); // Maybe<string>.Just with value "2" | ||
const newVal2 = v2.mapNullable(a => a.toString()); // Maybe<string>.None without value | ||
const newVal3 = v2.mapNullable<string | null>(a => null); // Maybe<string>.None without value | ||
const newVal4 = v2.mapNullable<string | void>(a => undefined); // Maybe<string>.None without value | ||
``` | ||
#### `Maybe#mapNullable` | ||
```typescript | ||
function map<Val, NewVal>(fn: (val: Val) => NewVal): Maybe<NewVal>; | ||
``` | ||
- Returns mapped by `fn` function value wrapped by `Maybe` if `Maybe` is `Just` otherwise `None` | ||
Example: | ||
```typescript | ||
const v1 = just(2); | ||
const v2 = none<number>(); | ||
const newVal1 = v1.map(a => a.toString()); // Maybe<string>.Just with value "2" | ||
const newVal2 = v2.map(a => a.toString()); // Maybe<string>.None without value | ||
``` | ||
##### `Maybe#asyncMap` | ||
@@ -384,2 +421,22 @@ | ||
##### `Maybe#fold` | ||
```typescript | ||
function fold<C>(mapNone: () => C, mapJust: (value: T) => C): C; | ||
``` | ||
- Returns value mapped by one of mapper functions. If `Maybe` is `Just` then `mapJust` is result of `mapJust` | ||
is returned, otherwise return of `mapNone` gets returned. | ||
Example: | ||
```typescript | ||
const v1 = just(2); | ||
const v2 = none<number>(); | ||
// "just: 4" | ||
const newVal1 = v1.fold(() => 'none', value => 'just: '+value*2) | ||
// "none" | ||
const newVal2 = v1.fold(() => 'none', value => 'just: '+value*2) | ||
``` | ||
#### Helpers | ||
@@ -386,0 +443,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
462
22593
4
186
1