/
piped.ts
81 lines (72 loc) · 1.97 KB
/
piped.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* eslint-disable jsdoc/require-param -- We don't document the ops */
import { pipe } from "./pipe";
/**
* A dataLast version of `pipe` that could be used to provide more complex
* computations to functions that accept a function as a param (like `map`,
* `filter`, `groupBy`, etc.).
*
* The first function must be always annotated. Other functions are
* automatically inferred.
*
* @signature
* R.piped(...ops)(data);
* @example
* R.filter(
* [{ a: 1 }, { a: 2 }, { a: 3 }],
* R.piped(
* R.prop('a'),
* (x) => x % 2 === 0,
* ),
* ); // => [{ a: 2 }]
* @category Function
*/
export function piped<A, B>(op1: (input: A) => B): (value: A) => B;
export function piped<A, B, C>(
op1: (input: A) => B,
op2: (input: B) => C,
): (value: A) => C;
export function piped<A, B, C, D>(
op1: (input: A) => B,
op2: (input: B) => C,
op3: (input: C) => D,
): (value: A) => D;
export function piped<A, B, C, D, E>(
op1: (input: A) => B,
op2: (input: B) => C,
op3: (input: C) => D,
op4: (input: D) => E,
): (value: A) => E;
export function piped<A, B, C, D, E, F>(
op1: (input: A) => B,
op2: (input: B) => C,
op3: (input: C) => D,
op4: (input: D) => E,
op5: (input: E) => F,
): (value: A) => F;
export function piped<A, B, C, D, E, F, G>(
op1: (input: A) => B,
op2: (input: B) => C,
op3: (input: C) => D,
op4: (input: D) => E,
op5: (input: E) => F,
op6: (input: F) => G,
): (value: A) => G;
export function piped<A, B, C, D, E, F, G, H>(
op1: (input: A) => B,
op2: (input: B) => C,
op3: (input: C) => D,
op4: (input: D) => E,
op5: (input: E) => F,
op6: (input: F) => G,
op7: (input: G) => H,
): (value: A) => H;
export function piped(
...operations: ReadonlyArray<(input: unknown) => unknown>
) {
return (value: unknown): unknown =>
pipe(
value,
// @ts-expect-error [ts2556] - We can't avoid this error because pipe is typed for users and this is an internal function
...operations,
);
}