From f9a77c5c27aede4e5978eb55d9b7af781b680a1d Mon Sep 17 00:00:00 2001 From: João Augusto Costa Branco Marado Torres Date: Tue, 24 Jun 2025 12:08:41 -0300 Subject: feat!: initial commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: João Augusto Costa Branco Marado Torres --- src/utils/anonymous.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/utils/anonymous.ts (limited to 'src/utils/anonymous.ts') diff --git a/src/utils/anonymous.ts b/src/utils/anonymous.ts new file mode 100644 index 0000000..ddd28bd --- /dev/null +++ b/src/utils/anonymous.ts @@ -0,0 +1,25 @@ +export const identity = (x: T): T => x; +export const defined = (x: T | undefined | null): x is T => + x !== undefined && x !== null; +export const instanciate = (C: new (arg: A) => T): (arg: A) => T => { + return (arg: A): T => new C(arg); +}; +export const get = , K extends PropertyKey>( + key: K, +): (obj: T) => T[K] => +(obj: T): T[K] => obj[key]; +export const getCall = < + T extends Record unknown>, + K extends PropertyKey, +>( + key: K, + ...args: Parameters +): (obj: T) => ReturnType => +(obj: T): ReturnType => obj[key](...args) as ReturnType; +export const pass = (fn: (x: T) => void): (x: T) => T => (x: T): T => { + fn(x); + return x; +}; +export const equal = (x: T): (y: T) => boolean => (y: T): boolean => x === y; +export const extremeBy = (arr: number[], mode: "max" | "min"): number => + Math[mode](...arr); -- cgit v1.2.3