source: node_modules/es-toolkit/dist/compat/function/partial.d.ts

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 11.2 KB
RevLine 
[a762898]1import { Toolkit } from '../toolkit.js';
2
3type __ = Placeholder | Toolkit;
4/**
5 * Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
6 *
7 * The partial.placeholder value, which defaults to a `symbol`, may be used as a placeholder for partially applied arguments.
8 *
9 * @example
10 * const greet = (greeting: string, name: string) => `${greeting} ${name}`;
11 * const sayHello = partial(greet, _, 'world');
12 * console.log(sayHello('Hello')); // => 'Hello world'
13 */
14declare function partial<T1, T2, R>(func: (t1: T1, t2: T2) => R, plc1: __, arg2: T2): (t1: T1) => R;
15/**
16 * Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
17 *
18 * @example
19 * const calculate = (x: number, y: number, z: number) => x + y + z;
20 * const addToY = partial(calculate, _, 2);
21 * console.log(addToY(1, 3)); // => 6
22 */
23declare function partial<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, plc1: __, arg2: T2): (t1: T1, t3: T3) => R;
24/**
25 * Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
26 *
27 * @example
28 * const calculate = (x: number, y: number, z: number) => x + y + z;
29 * const addZ = partial(calculate, _, _, 3);
30 * console.log(addZ(1, 2)); // => 6
31 */
32declare function partial<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, plc1: __, plc2: __, arg3: T3): (t1: T1, t2: T2) => R;
33/**
34 * Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
35 *
36 * @example
37 * const calculate = (x: number, y: number, z: number) => x + y + z;
38 * const withXandZ = partial(calculate, 1, _, 3);
39 * console.log(withXandZ(2)); // => 6
40 */
41declare function partial<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arg1: T1, plc2: __, arg3: T3): (t2: T2) => R;
42/**
43 * Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
44 *
45 * @example
46 * const calculate = (x: number, y: number, z: number) => x + y + z;
47 * const withYandZ = partial(calculate, _, 2, 3);
48 * console.log(withYandZ(1)); // => 6
49 */
50declare function partial<T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, plc1: __, arg2: T2, arg3: T3): (t1: T1) => R;
51/**
52 * Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
53 *
54 * @example
55 * const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
56 * const withB = partial(format, _, 'b');
57 * console.log(withB('a', 'c', 'd')); // => 'a-b-c-d'
58 */
59declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, plc1: __, arg2: T2): (t1: T1, t3: T3, t4: T4) => R;
60/**
61 * Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
62 *
63 * @example
64 * const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
65 * const withC = partial(format, _, _, 'c');
66 * console.log(withC('a', 'b', 'd')); // => 'a-b-c-d'
67 */
68declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, plc1: __, plc2: __, arg3: T3): (t1: T1, t2: T2, t4: T4) => R;
69/**
70 * Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
71 *
72 * @example
73 * const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
74 * const withAandC = partial(format, 'a', _, 'c');
75 * console.log(withAandC('b', 'd')); // => 'a-b-c-d'
76 */
77declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, plc2: __, arg3: T3): (t2: T2, t4: T4) => R;
78/**
79 * Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
80 *
81 * @example
82 * const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
83 * const withBandC = partial(format, _, 'b', 'c');
84 * console.log(withBandC('a', 'd')); // => 'a-b-c-d'
85 */
86declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, plc1: __, arg2: T2, arg3: T3): (t1: T1, t4: T4) => R;
87/**
88 * Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
89 *
90 * @example
91 * const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
92 * const withD = partial(format, _, _, _, 'd');
93 * console.log(withD('a', 'b', 'c')); // => 'a-b-c-d'
94 */
95declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, plc1: __, plc2: __, plc3: __, arg4: T4): (t1: T1, t2: T2, t3: T3) => R;
96/**
97 * Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
98 *
99 * @example
100 * const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
101 * const withAandD = partial(format, 'a', _, _, 'd');
102 * console.log(withAandD('b', 'c')); // => 'a-b-c-d'
103 */
104declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, plc2: __, plc3: __, arg4: T4): (t2: T2, t3: T3) => R;
105/**
106 * Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
107 *
108 * @example
109 * const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
110 * const withBandD = partial(format, _, 'b', _, 'd');
111 * console.log(withBandD('a', 'c')); // => 'a-b-c-d'
112 */
113declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, plc1: __, arg2: T2, plc3: __, arg4: T4): (t1: T1, t3: T3) => R;
114/**
115 * Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
116 *
117 * @example
118 * const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
119 * const withABandD = partial(format, 'a', 'b', _, 'd');
120 * console.log(withABandD('c')); // => 'a-b-c-d'
121 */
122declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, arg2: T2, plc3: __, arg4: T4): (t3: T3) => R;
123/**
124 * Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
125 *
126 * @example
127 * const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
128 * const withCandD = partial(format, _, _, 'c', 'd');
129 * console.log(withCandD('a', 'b')); // => 'a-b-c-d'
130 */
131declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, plc1: __, plc2: __, arg3: T3, arg4: T4): (t1: T1, t2: T2) => R;
132/**
133 * Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
134 *
135 * @example
136 * const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
137 * const withACandD = partial(format, 'a', _, 'c', 'd');
138 * console.log(withACandD('b')); // => 'a-b-c-d'
139 */
140declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arg1: T1, plc2: __, arg3: T3, arg4: T4): (t2: T2) => R;
141/**
142 * Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
143 *
144 * @example
145 * const format = (a: string, b: string, c: string, d: string) => `${a}-${b}-${c}-${d}`;
146 * const withBCandD = partial(format, _, 'b', 'c', 'd');
147 * console.log(withBCandD('a')); // => 'a-b-c-d'
148 */
149declare function partial<T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, plc1: __, arg2: T2, arg3: T3, arg4: T4): (t1: T1) => R;
150/**
151 * Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
152 *
153 * @example
154 * const sum = (...numbers: number[]) => numbers.reduce((a, b) => a + b, 0);
155 * const partialSum = partial(sum);
156 * console.log(partialSum(1, 2, 3)); // => 6
157 */
158declare function partial<TS extends any[], R>(func: (...ts: TS) => R): (...ts: TS) => R;
159/**
160 * Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
161 *
162 * @example
163 * const log = (prefix: string, ...messages: string[]) => console.log(prefix, ...messages);
164 * const debugLog = partial(log, '[DEBUG]');
165 * debugLog('message 1', 'message 2'); // => '[DEBUG] message 1 message 2'
166 */
167declare function partial<TS extends any[], T1, R>(func: (t1: T1, ...ts: TS) => R, arg1: T1): (...ts: TS) => R;
168/**
169 * Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
170 *
171 * @example
172 * const format = (prefix: string, separator: string, ...messages: string[]) => `${prefix}${messages.join(separator)}`;
173 * const logWithPrefix = partial(format, '[LOG]', ' - ');
174 * console.log(logWithPrefix('msg1', 'msg2')); // => '[LOG]msg1 - msg2'
175 */
176declare function partial<TS extends any[], T1, T2, R>(func: (t1: T1, t2: T2, ...ts: TS) => R, t1: T1, t2: T2): (...ts: TS) => R;
177/**
178 * Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
179 *
180 * @example
181 * const format = (type: string, level: string, message: string, ...tags: string[]) =>
182 * `[${type}][${level}] ${message} ${tags.join(',')}`;
183 * const errorLog = partial(format, 'ERROR', 'HIGH', 'Something went wrong');
184 * console.log(errorLog('critical', 'urgent')); // => '[ERROR][HIGH] Something went wrong critical,urgent'
185 */
186declare function partial<TS extends any[], T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3, ...ts: TS) => R, t1: T1, t2: T2, t3: T3): (...ts: TS) => R;
187/**
188 * Creates a function that invokes `func` with `partialArgs` prepended to the arguments it receives. This method is like `bind` except it does not alter the `this` binding.
189 *
190 * @example
191 * const format = (a: string, b: string, c: string, d: string, ...rest: string[]) =>
192 * `${a}-${b}-${c}-${d}:${rest.join(',')}`;
193 * const prefixedFormat = partial(format, 'a', 'b', 'c', 'd');
194 * console.log(prefixedFormat('e', 'f')); // => 'a-b-c-d:e,f'
195 */
196declare function partial<TS extends any[], T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4, ...ts: TS) => R, t1: T1, t2: T2, t3: T3, t4: T4): (...ts: TS) => R;
197declare namespace partial {
198 var placeholder: Placeholder;
199}
200type Placeholder = symbol | (((value: any) => any) & {
201 partial: typeof partial;
202});
203
204export { partial };
Note: See TracBrowser for help on using the repository browser.