deno.land / x / froebel@v0.23.2 / callAll.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 { λ } from "./types.ts";
/** * Take a list of functions that accept the same parameters and call them all * with the provided arguments. * * @example * ``` * const mult = (a: number, b: number) => a * b * const div = (a: number, b: number) => a / b * * // prints: [8, 2] * console.log( callAll([mult, div], 4, 2) ) * ``` */const callAll = <P extends any[], F extends λ<P>[]>( funs: [...F], ...args: P): ReturnTypes<F> => (funs.map((cb) => cb(...args)) ?? []) as any;
type ReturnTypes<T extends λ[]> = { [K in keyof T]: T[K] extends λ<any, infer I> ? I : never;};
export default callAll;
froebel

Version Info

Tagged at
a year ago