flowRight
Import from @varavel/vdl-plugin-sdk/utils/functions.
Utility functions re-exported from es-toolkit (MIT License).
See https://github.com/toss/es-toolkit for more details.
Call Signature
Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
The this context of the returned function is also passed to the functions provided as parameters.
This method is like flow except that it creates a function that invokes the given functions from right to left.
Type Parameters
| Type Parameter |
|---|
R |
Parameters
| Parameter | Type | Description |
|---|---|---|
f |
() => R |
The function to invoke. |
Returns
Returns the new composite function.
() => R
Example
function noArgFunc() {
return 42;
}
const combined = flowRight(noArgFunc);
console.log(combined()); // 42
Call Signature
Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
The this context of the returned function is also passed to the functions provided as parameters.
This method is like flow except that it creates a function that invokes the given functions from right to left.
Type Parameters
| Type Parameter |
|---|
A extends any[] |
R |
Parameters
| Parameter | Type | Description |
|---|---|---|
f1 |
(...args) => R |
The function to invoke. |
Returns
Returns the new composite function.
(...args) => R
Example
function oneArgFunc(a: number) {
return a * 2;
}
const combined = flowRight(oneArgFunc);
console.log(combined(5)); // 10
Call Signature
Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
The this context of the returned function is also passed to the functions provided as parameters.
This method is like flow except that it creates a function that invokes the given functions from right to left.
Type Parameters
| Type Parameter |
|---|
A extends any[] |
R1 |
R2 |
Parameters
| Parameter | Type | Description |
|---|---|---|
f2 |
(a) => R2 |
The function to invoke. |
f1 |
(...args) => R1 |
The function to invoke. |
Returns
Returns the new composite function.
(...args) => R2
Example
const add = (x: number, y: number) => x + y;
const square = (n: number) => n * n;
const combined = flowRight(square, add);
console.log(combined(1, 2)); // 9
Call Signature
Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
The this context of the returned function is also passed to the functions provided as parameters.
This method is like flow except that it creates a function that invokes the given functions from right to left.
Type Parameters
| Type Parameter |
|---|
A extends any[] |
R1 |
R2 |
R3 |
Parameters
| Parameter | Type | Description |
|---|---|---|
f3 |
(a) => R3 |
The function to invoke. |
f2 |
(a) => R2 |
The function to invoke. |
f1 |
(...args) => R1 |
The function to invoke. |
Returns
Returns the new composite function.
(...args) => R3
Example
const add = (x: number, y: number) => x + y;
const square = (n: number) => n * n;
const double = (n: number) => n * 2;
const combined = flowRight(double, square, add);
console.log(combined(1, 2)); // 18
Call Signature
Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
The this context of the returned function is also passed to the functions provided as parameters.
This method is like flow except that it creates a function that invokes the given functions from right to left.
Type Parameters
| Type Parameter |
|---|
A extends any[] |
R1 |
R2 |
R3 |
R4 |
Parameters
| Parameter | Type | Description |
|---|---|---|
f4 |
(a) => R4 |
The function to invoke. |
f3 |
(a) => R3 |
The function to invoke. |
f2 |
(a) => R2 |
The function to invoke. |
f1 |
(...args) => R1 |
The function to invoke. |
Returns
Returns the new composite function.
(...args) => R4
Example
const add = (x: number, y: number) => x + y;
const square = (n: number) => n * n;
const double = (n: number) => n * 2;
const toStr = (n: number) => n.toString();
const combined = flowRight(toStr, double, square, add);
console.log(combined(1, 2)); // '18'
Call Signature
Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
The this context of the returned function is also passed to the functions provided as parameters.
This method is like flow except that it creates a function that invokes the given functions from right to left.
Type Parameters
| Type Parameter |
|---|
A extends any[] |
R1 |
R2 |
R3 |
R4 |
R5 |
Parameters
| Parameter | Type | Description |
|---|---|---|
f5 |
(a) => R5 |
The function to invoke. |
f4 |
(a) => R4 |
The function to invoke. |
f3 |
(a) => R3 |
The function to invoke. |
f2 |
(a) => R2 |
The function to invoke. |
f1 |
(...args) => R1 |
The function to invoke. |
Returns
Returns the new composite function.
(...args) => R5
Example
const add = (x: number, y: number) => x + y;
const square = (n: number) => n * n;
const double = (n: number) => n * 2;
const toStr = (n: number) => n.toString();
const split = (s: string) => s.split('');
const combined = flowRight(split, toStr, double, square, add);
console.log(combined(1, 2)); // ['1', '8']
Call Signature
Creates a new function that executes the given functions in sequence from right to left. The return value of the previous function is passed as an argument to the next function.
The this context of the returned function is also passed to the functions provided as parameters.
This method is like flow except that it creates a function that invokes the given functions from right to left.
Parameters
| Parameter | Type | Description |
|---|---|---|
...funcs |
(...args) => any[] |
The functions to invoke. |
Returns
Returns the new composite function.
(...args) => any