deno.land / x / froebel@v0.23.2 / partial.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
import type { PartialList, λ } from "./types.ts";
/** * Partially apply a function. * * @example * ``` * const divide = (dividend: number, divisor: number) => dividend / divisor * * // (divisor: number) => number * const oneOver = partial(divide, 1) * * // prints: 0.25 * console.log(oneOver(4)) * ``` */const partial = <T extends λ, PL extends PartialList<Parameters<T>>>( fun: T, ...argsLeft: PL) =>( ...argsRight: Parameters<T> extends [...PL, ...infer PR] ? PR : never): ReturnType<T> => fun(...argsLeft, ...argsRight);
export default partial;
froebel

Version Info

Tagged at
a year ago