@solana/functional 6.3.1 → 6.3.2-canary-20260313143218

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/functional",
3
- "version": "6.3.1",
3
+ "version": "6.3.2-canary-20260313143218",
4
4
  "description": "Functional JavaScript helpers",
5
5
  "homepage": "https://www.solanakit.com/api#solanafunctional",
6
6
  "exports": {
@@ -33,7 +33,8 @@
33
33
  "types": "./dist/types/index.d.ts",
34
34
  "type": "commonjs",
35
35
  "files": [
36
- "./dist/"
36
+ "./dist/",
37
+ "./src/"
37
38
  ],
38
39
  "sideEffects": false,
39
40
  "keywords": [
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * This package contains generalized functional helpers and functional helpers specific to Solana application components. It can be used standalone, but it is also exported as part of Kit [`@solana/kit`](https://github.com/anza-xyz/kit/tree/main/packages/kit).
3
+ * @packageDocumentation
4
+ */
5
+ export * from './pipe';
package/src/pipe.ts ADDED
@@ -0,0 +1,236 @@
1
+ /**
2
+ * A pipeline is a solution that allows you to perform successive transforms of a value using functions. This is useful when building up a transaction message.
3
+ *
4
+ * Until the [pipeline operator](https://github.com/tc39/proposal-pipeline-operator) becomes part of JavaScript you can use this utility to create pipelines.
5
+ *
6
+ * Following common implementations of pipe functions that use TypeScript, this function supports a maximum arity of 10 for type safety.
7
+ *
8
+ * Note you can use nested pipes to extend this limitation, like so:
9
+ * ```ts
10
+ * const myValue = pipe(
11
+ * pipe(
12
+ * 1,
13
+ * (x) => x + 1,
14
+ * (x) => x * 2,
15
+ * (x) => x - 1,
16
+ * ),
17
+ * (y) => y / 3,
18
+ * (y) => y + 1,
19
+ * );
20
+ * ```
21
+ *
22
+ * @see https://github.com/ramda/ramda/blob/master/source/pipe.js
23
+ * @see https://github.com/darky/rocket-pipes/blob/master/index.ts
24
+ *
25
+ * @example Basic
26
+ * ```ts
27
+ * const add = (a, b) => a + b;
28
+ * const add10 = x => add(x, 10);
29
+ * const add100 = x => add(x, 100);
30
+ * const sum = pipe(1, add10, add100);
31
+ * sum === 111; // true
32
+ * ```
33
+ *
34
+ * @example Building a Solana transaction message
35
+ * ```ts
36
+ * const transferTransactionMessage = pipe(
37
+ * // The result of the first expression...
38
+ * createTransactionMessage({ version: 0 }),
39
+ * // ...gets passed as the sole argument to the next function in the pipeline.
40
+ * tx => setTransactionMessageFeePayer(myAddress, tx),
41
+ * // The return value of that function gets passed to the next...
42
+ * tx => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, tx),
43
+ * // ...and so on.
44
+ * tx => appendTransactionMessageInstruction(createTransferInstruction(myAddress, toAddress, amountInLamports), tx),
45
+ * );
46
+ * ```
47
+ *
48
+ * @returns The initial value
49
+ */
50
+ export function pipe<TInitial>(
51
+ /** The initial value */
52
+ init: TInitial,
53
+ ): TInitial;
54
+ /**
55
+ * @returns The return value of the final transform function
56
+ */
57
+ export function pipe<TInitial, R1>(
58
+ /** The initial value */
59
+ init: TInitial,
60
+ /** The function with which to transform the initial value */
61
+ init_r1: (init: TInitial) => R1,
62
+ ): R1;
63
+ /**
64
+ * @returns The return value of the final transform function
65
+ */
66
+ export function pipe<TInitial, R1, R2>(
67
+ /** The initial value */
68
+ init: TInitial,
69
+ /** The function with which to transform the initial value */
70
+ init_r1: (init: TInitial) => R1,
71
+ /** The function with which to transform the return value of the prior function */
72
+ r1_r2: (r1: R1) => R2,
73
+ ): R2;
74
+ /**
75
+ * @returns The return value of the final transform function
76
+ */
77
+ export function pipe<TInitial, R1, R2, R3>(
78
+ /** The initial value */
79
+ init: TInitial,
80
+ /** The function with which to transform the initial value */
81
+ init_r1: (init: TInitial) => R1,
82
+ /** The function with which to transform the return value of the prior function */
83
+ r1_r2: (r1: R1) => R2,
84
+ /** The function with which to transform the return value of the prior function */
85
+ r2_r3: (r2: R2) => R3,
86
+ ): R3;
87
+ /**
88
+ * @returns The return value of the final transform function
89
+ */
90
+ export function pipe<TInitial, R1, R2, R3, R4>(
91
+ /** The initial value */
92
+ init: TInitial,
93
+ /** The function with which to transform the initial value */
94
+ init_r1: (init: TInitial) => R1,
95
+ /** The function with which to transform the return value of the prior function */
96
+ r1_r2: (r1: R1) => R2,
97
+ /** The function with which to transform the return value of the prior function */
98
+ r2_r3: (r2: R2) => R3,
99
+ /** The function with which to transform the return value of the prior function */
100
+ r3_r4: (r3: R3) => R4,
101
+ ): R4;
102
+ /**
103
+ * @returns The return value of the final transform function
104
+ */
105
+ export function pipe<TInitial, R1, R2, R3, R4, R5>(
106
+ /** The initial value */
107
+ init: TInitial,
108
+ /** The function with which to transform the initial value */
109
+ init_r1: (init: TInitial) => R1,
110
+ /** The function with which to transform the return value of the prior function */
111
+ r1_r2: (r1: R1) => R2,
112
+ /** The function with which to transform the return value of the prior function */
113
+ r2_r3: (r2: R2) => R3,
114
+ /** The function with which to transform the return value of the prior function */
115
+ r3_r4: (r3: R3) => R4,
116
+ /** The function with which to transform the return value of the prior function */
117
+ r4_r5: (r4: R4) => R5,
118
+ ): R5;
119
+ /**
120
+ * @returns The return value of the final transform function
121
+ */
122
+ export function pipe<TInitial, R1, R2, R3, R4, R5, R6>(
123
+ /** The initial value */
124
+ init: TInitial,
125
+ /** The function with which to transform the initial value */
126
+ init_r1: (init: TInitial) => R1,
127
+ /** The function with which to transform the return value of the prior function */
128
+ r1_r2: (r1: R1) => R2,
129
+ /** The function with which to transform the return value of the prior function */
130
+ r2_r3: (r2: R2) => R3,
131
+ /** The function with which to transform the return value of the prior function */
132
+ r3_r4: (r3: R3) => R4,
133
+ /** The function with which to transform the return value of the prior function */
134
+ r4_r5: (r4: R4) => R5,
135
+ /** The function with which to transform the return value of the prior function */
136
+ r5_r6: (r5: R5) => R6,
137
+ ): R6;
138
+ /**
139
+ * @returns The return value of the final transform function
140
+ */
141
+ export function pipe<TInitial, R1, R2, R3, R4, R5, R6, R7>(
142
+ /** The initial value */
143
+ init: TInitial,
144
+ /** The function with which to transform the initial value */
145
+ init_r1: (init: TInitial) => R1,
146
+ /** The function with which to transform the return value of the prior function */
147
+ r1_r2: (r1: R1) => R2,
148
+ /** The function with which to transform the return value of the prior function */
149
+ r2_r3: (r2: R2) => R3,
150
+ /** The function with which to transform the return value of the prior function */
151
+ r3_r4: (r3: R3) => R4,
152
+ /** The function with which to transform the return value of the prior function */
153
+ r4_r5: (r4: R4) => R5,
154
+ /** The function with which to transform the return value of the prior function */
155
+ r5_r6: (r5: R5) => R6,
156
+ /** The function with which to transform the return value of the prior function */
157
+ r6_r7: (r6: R6) => R7,
158
+ ): R7;
159
+ /**
160
+ * @returns The return value of the final transform function
161
+ */
162
+ export function pipe<TInitial, R1, R2, R3, R4, R5, R6, R7, R8>(
163
+ /** The initial value */
164
+ init: TInitial,
165
+ /** The function with which to transform the initial value */
166
+ init_r1: (init: TInitial) => R1,
167
+ /** The function with which to transform the return value of the prior function */
168
+ r1_r2: (r1: R1) => R2,
169
+ /** The function with which to transform the return value of the prior function */
170
+ r2_r3: (r2: R2) => R3,
171
+ /** The function with which to transform the return value of the prior function */
172
+ r3_r4: (r3: R3) => R4,
173
+ /** The function with which to transform the return value of the prior function */
174
+ r4_r5: (r4: R4) => R5,
175
+ /** The function with which to transform the return value of the prior function */
176
+ r5_r6: (r5: R5) => R6,
177
+ /** The function with which to transform the return value of the prior function */
178
+ r6_r7: (r6: R6) => R7,
179
+ /** The function with which to transform the return value of the prior function */
180
+ r7_r8: (r7: R7) => R8,
181
+ ): R8;
182
+ /**
183
+ * @returns The return value of the final transform function
184
+ */
185
+ export function pipe<TInitial, R1, R2, R3, R4, R5, R6, R7, R8, R9>(
186
+ /** The initial value */
187
+ init: TInitial,
188
+ /** The function with which to transform the initial value */
189
+ init_r1: (init: TInitial) => R1,
190
+ /** The function with which to transform the return value of the prior function */
191
+ r1_r2: (r1: R1) => R2,
192
+ /** The function with which to transform the return value of the prior function */
193
+ r2_r3: (r2: R2) => R3,
194
+ /** The function with which to transform the return value of the prior function */
195
+ r3_r4: (r3: R3) => R4,
196
+ /** The function with which to transform the return value of the prior function */
197
+ r4_r5: (r4: R4) => R5,
198
+ /** The function with which to transform the return value of the prior function */
199
+ r5_r6: (r5: R5) => R6,
200
+ /** The function with which to transform the return value of the prior function */
201
+ r6_r7: (r6: R6) => R7,
202
+ /** The function with which to transform the return value of the prior function */
203
+ r7_r8: (r7: R7) => R8,
204
+ /** The function with which to transform the return value of the prior function */
205
+ r8_r9: (r8: R8) => R9,
206
+ ): R9;
207
+ /**
208
+ * @returns The return value of the final transform function
209
+ */
210
+ export function pipe<TInitial, R1, R2, R3, R4, R5, R6, R7, R8, R9, R10>(
211
+ /** The initial value */
212
+ init: TInitial,
213
+ /** The function with which to transform the initial value */
214
+ init_r1: (init: TInitial) => R1,
215
+ /** The function with which to transform the return value of the prior function */
216
+ r1_r2: (r1: R1) => R2,
217
+ /** The function with which to transform the return value of the prior function */
218
+ r2_r3: (r2: R2) => R3,
219
+ /** The function with which to transform the return value of the prior function */
220
+ r3_r4: (r3: R3) => R4,
221
+ /** The function with which to transform the return value of the prior function */
222
+ r4_r5: (r4: R4) => R5,
223
+ /** The function with which to transform the return value of the prior function */
224
+ r5_r6: (r5: R5) => R6,
225
+ /** The function with which to transform the return value of the prior function */
226
+ r6_r7: (r6: R6) => R7,
227
+ /** The function with which to transform the return value of the prior function */
228
+ r7_r8: (r7: R7) => R8,
229
+ /** The function with which to transform the return value of the prior function */
230
+ r8_r9: (r8: R8) => R9,
231
+ /** The function with which to transform the return value of the prior function */
232
+ r9_r10: (r9: R9) => R10,
233
+ ): R10;
234
+ export function pipe<TInitial>(init: TInitial, ...fns: CallableFunction[]) {
235
+ return fns.reduce((acc, fn) => fn(acc), init);
236
+ }