withFallback
This function returns a new function that either returns the result of func or a fallback value defaultValue if the result is null or undefined.
Added in v0.0.2
Usage
ts
import { withFallback } from 'parsnip-kit'
const func = (a: number) => (a === 0 ? null : a)
const funcWithDefault = withFallback(func, -1)
funcWithDefault(1)
// 1
funcWithDefault(0)
// -1API
Type Parameter
| Arg | Type | Description |
|---|---|---|
T | extends (...args: any[]) => any | Function type |
R | | Type of default value |
Arguments
| Arg | Type | Optional | Default | Description |
|---|---|---|---|---|
func | T | false | undefined | The function with default return value |
defaultValue | R | false | undefined | Default value |
Returns
| Type |
|---|
WithFallback<T, R> |