Resolves a value that was provided via ValueOrProvider
Can be called with optional args which will be used as arguments when calling the Provider Function.
args
Create a Function that accepts a value that can be either lazy and eager inizialized
value
function fn(value: ValueOrProvider<string>) { // ... some code that may return early from the Function ... // resolve the value when it is actually needed const actualValue = valueOrProviderResult(value); console.log(typeof actualValue); // 'string'}
Call the Function with an eager initialized value
fn(1);
Call the Function with a lazy initialized value
function someExpensiveOperation() { /* ... */ }fn(someExpensiveOperation);
Create a Function that accepts a value that can be either static or dynamic
function add(numbers: number[], value: ValueOrProvider<number, [number]>) { return numbers.map(n => n + valueOrProviderResult(value, e));}
Call the Function with a static value
const a = add([1,2,3], 1);console.log(a); // [2,3,4]
Call the Function with a dynamic value
const a = add([1,2,3], n => 2+n);console.log(a); // [4,6,8]
the result of the Function if value is a Function, otherwise returns value itself
Rest
Generated using TypeDoc
Resolves a value that was provided via ValueOrProvider
Can be called with optional
argswhich will be used as arguments when calling the Provider Function.Example
Create a Function that accepts a
valuethat can be either lazy and eager inizializedCall the Function with an eager initialized value
Call the Function with a lazy initialized value
Example
Create a Function that accepts a
valuethat can be either static or dynamicCall the Function with a static value
Call the Function with a dynamic value
Returns
the result of the Function if
valueis a Function, otherwise returnsvalueitself