Options
All
  • Public
  • Public/Protected
  • All
Menu

Package lambda

@typed/lambda

Functions for working with other functions.

Index

Type aliases

Apply

Apply<Args, T>: T extends (...args: Args) => infer R ? R : never

Type parameters

  • Args: keyof any[]

  • T: Fn<Args>

ArgsOf

ArgsOf<T>: T extends Fn<infer Args, any> ? Args : []

Type parameters

Arity1

Arity1<A, B>: (value: A) => B

Type parameters

  • A

  • B

Type declaration

    • (value: A): B
    • Parameters

      • value: A

      Returns B

Arity2

Arity2<A, B, C>: (a: A, b: B) => C

Type parameters

  • A

  • B

  • C

Type declaration

    • (a: A, b: B): C
    • Parameters

      • a: A
      • b: B

      Returns C

Arity3

Arity3<A, B, C, D>: (a: A, b: B, c: C) => D

Type parameters

  • A

  • B

  • C

  • D

Type declaration

    • (a: A, b: B, c: C): D
    • Parameters

      • a: A
      • b: B
      • c: C

      Returns D

Arity4

Arity4<A, B, C, D, E>: (a: A, b: B, c: C, d: D) => E

Type parameters

  • A

  • B

  • C

  • D

  • E

Type declaration

    • (a: A, b: B, c: C, d: D): E
    • Parameters

      • a: A
      • b: B
      • c: C
      • d: D

      Returns E

Arity5

Arity5<A, B, C, D, E, F>: (a: A, b: B, c: C, d: D, e: E) => F

Type parameters

  • A

  • B

  • C

  • D

  • E

  • F

Type declaration

    • (a: A, b: B, c: C, d: D, e: E): F
    • Parameters

      • a: A
      • b: B
      • c: C
      • d: D
      • e: E

      Returns F

ComparableValues

ComparableValues: keyof any | boolean | Date

ComparisonNumbers

ComparisonNumbers: -1 | 0 | 1

Curry

Curry<T>: ArgsOf<T> extends [infer A] ? Arity1<A, ReturnType<T>> : ArgsOf<T> extends [infer A, infer B] ? Curry2<A, B, ReturnType<T>> : ArgsOf<T> extends [infer A, infer B, infer C] ? Curry3<A, B, C, ReturnType<T>> : ArgsOf<T> extends [infer A, infer B, infer C, infer D] ? Curry4<A, B, C, D, ReturnType<T>> : ArgsOf<T> extends [infer A, infer B, infer C, infer D, infer E] ? Curry5<A, B, C, D, E, ReturnType<T>> : ArgsOf<T> extends never[] ? IO<ReturnType<T>> : never

Type parameters

CurryObj

CurryObj<A, B>: <C>(c: C) => C extends A ? B : CurryObj<Required<{}>, B>

Type parameters

  • A: {}

  • B

Type declaration

    • <C>(c: C): C extends A ? B : CurryObj<Required<{}>, B>
    • Type parameters

      • C: Partial<A>

      Parameters

      • c: C

      Returns C extends A ? B : CurryObj<Required<{}>, B>

Defined

Defined<T>: T extends undefined ? never : T

Type parameters

  • T

Flip

Flip<T>: ArgsOf<T> extends [] ? Fn<[], ReturnType<T>> : ArgsOf<T> extends [infer A] ? Fn<[A], ReturnType<T>> : ArgsOf<T> extends [infer A, infer B] ? Fn<[B, A], ReturnType<T>> : ArgsOf<T> extends [infer A, infer B, infer C] ? Fn<[B, A, C], ReturnType<T>> : ArgsOf<T> extends [infer A, infer B, infer C, infer D] ? Fn<[B, A, C, D], ReturnType<T>> : ArgsOf<T> extends [infer A, infer B, infer C, infer D, infer E] ? Fn<[B, A, C, D, E], ReturnType<T>> : never

Type parameters

Fn

Fn<Args, R>: (...args: Args) => R

Type parameters

  • Args: keyof any[]

  • R

Type declaration

    • (...args: Args): R
    • Parameters

      • Rest ...args: Args

      Returns R

Head

Head<A>: HeadArg<Fn<A>>

Type parameters

  • A: keyof any[]

HeadArg

HeadArg<F>: F extends (head: infer A, ...tail: any[]) => any ? A : never

Type parameters

  • F: Function

IO

IO<A>: () => A

Type parameters

  • A

Type declaration

    • (): A
    • Returns A

Include

Include<A, B>: A extends B ? A : never

Type parameters

  • A

  • B

Init

Init<A, B>: CastArray<{}>

Type parameters

  • A: keyof any[]

  • B: keyof any[]

InitArgsOf

InitArgsOf<F>: Init<ArgsOf<F>>

Type parameters

Is

Is<A>: (value: unknown) => value is A

Type parameters

  • A

Type declaration

    • (value: unknown): value is A
    • Parameters

      • value: unknown

      Returns value is A

IsNot

IsNot<A>: <B>(value: A | B) => value is B

Type parameters

  • A

Type declaration

    • <B>(value: A | B): value is B
    • Type parameters

      • B: unknown

      Parameters

      • value: A | B

      Returns value is B

OrToAnd

OrToAnd<A>:

Type parameters

  • A

PartialArgsOf

PartialArgsOf<T>: T extends (...args: infer TArgs) => any ? Partial<TArgs> : never

Type parameters

Predicate

Predicate<A>: Arity1<A, boolean>

Type parameters

  • A

Predicate2

Predicate2<A, B>: Arity2<A, B, boolean>

Type parameters

  • A

  • B

Primitive

Primitive: undefined | null | boolean | string | number | Function

Refinement

Refinement<A, B>: (a: A) => a is B

Type parameters

  • A

  • B: A

Type declaration

    • (a: A): a is B
    • Parameters

      • a: A

      Returns a is B

Tail

Tail<A>: TailArgsOf<Fn<A>>

Type parameters

  • A: keyof any[]

TailArgsOf

TailArgsOf<F>: F extends (head: any, ...tail: infer TTail) => any ? TTail : never

Type parameters

  • F: Function

TypeGuard

TypeGuard<A, B>: (value: A) => value is B

Type parameters

  • A

  • B: A

Type declaration

    • (value: A): value is B
    • Parameters

      • value: A

      Returns value is B

Uncurry

Uncurry<Fun>: Fun extends (a: infer A) => (b: infer B) => (c: infer C) => (d: infer D) => (e: infer E) => infer F ? (a: A, b: B, c: C, d: D, e: E) => F : Fun extends (a: infer A) => (b: infer B) => (c: infer C) => (d: infer D) => infer E ? (a: A, b: B, c: C, d: D) => E : Fun extends (a: infer A) => (b: infer B) => (c: infer C) => infer D ? (a: A, b: B, c: C) => D : Fun extends (a: infer A) => (b: infer B) => infer C ? (a: A, b: B) => C : Fun

Type parameters

Variables

Const apply

apply: { <Args, T>(args: Args, fn: T): Apply<Args, T>; <Args>(args: Args): <T>(fn: T) => Apply<Args, T> } = curry(<Args extends readonly any[], T extends Fn<Args>>(args: Args, fn: T): Apply<Args, T> =>fn(...args),) as {<Args extends readonly any[], T extends Fn<Args>>(args: Args, fn: T): Apply<Args, T><Args extends readonly any[]>(args: Args): <T extends Fn<Args>>(fn: T) => Apply<Args, T>}

Call a function with a list of arguments

param

List of arguments

param

Function to call

Type declaration

    • <Args, T>(args: Args, fn: T): Apply<Args, T>
    • <Args>(args: Args): <T>(fn: T) => Apply<Args, T>
    • Type parameters

      • Args: keyof any[]

      • T: Fn<Args>

      Parameters

      • args: Args
      • fn: T

      Returns Apply<Args, T>

    • Type parameters

      • Args: keyof any[]

      Parameters

      • args: Args

      Returns <T>(fn: T) => Apply<Args, T>

        • <T>(fn: T): Apply<Args, T>
        • Type parameters

          • T: Fn<Args>

          Parameters

          • fn: T

          Returns Apply<Args, T>

Const pipe

pipe: Pipe = ((...fns: Arity1[]) =>fns.length > 1 ? fns.slice(1).reduce(pipe2, fns[0]) : fns[0]) as Pipe

Generic Left-to-right composition

Const tap

tap: { <A>(fn: Arity1<A>, value: A): A; <A>(fn: Arity1<A>): (value: A) => A } = curry(<A>(fn: Arity1<A>, value: A): A => {fn(value)return value},)

Perform a side-effect with a value and return the given value.

param

:: (a -> *)

param

:: a

returns

a

Type declaration

    • <A>(fn: Arity1<A>, value: A): A
    • <A>(fn: Arity1<A>): (value: A) => A
    • Type parameters

      • A

      Parameters

      Returns A

    • Type parameters

      • A

      Parameters

      Returns (value: A) => A

        • (value: A): A
        • Parameters

          • value: A

          Returns A

Const withPrevious

withPrevious: { <A, Args>(withFn: Arity1<A>, fn: Fn<Args, A>): Fn<Args, A>; <A>(withFn: Arity1<A>): <Args>(fn: Fn<Args, A>) => Fn<Args, A> } = curry(function withPrevious<A, Args extends any[]>(withFn: Arity1<A, void>,fn: Fn<Args, A>,): Fn<Args, A> {let previous: Maybe<A> = { [NOTHING]: true }return (...args: Args): A => {if (!isNothing(previous)) {withFn(previous.value)}const value = fn(...args)previous = { [NOTHING]: false, value }return value}}) as {<A, Args extends any[]>(withFn: Arity1<A>, fn: Fn<Args, A>): Fn<Args, A><A>(withFn: Arity1<A>): <Args extends any[]>(fn: Fn<Args, A>) => Fn<Args, A>}

Perform an operation with the previous value returned

param

:: (a -> *)

param

(...* -> a)

returns

(...* -> a)

Type declaration

    • <A, Args>(withFn: Arity1<A>, fn: Fn<Args, A>): Fn<Args, A>
    • <A>(withFn: Arity1<A>): <Args>(fn: Fn<Args, A>) => Fn<Args, A>
    • Type parameters

      • A

      • Args: any[]

      Parameters

      Returns Fn<Args, A>

    • Type parameters

      • A

      Parameters

      Returns <Args>(fn: Fn<Args, A>) => Fn<Args, A>

        • <Args>(fn: Fn<Args, A>): Fn<Args, A>
        • Type parameters

          • Args: any[]

          Parameters

          • fn: Fn<Args, A>

          Returns Fn<Args, A>

Functions

Const always

  • always<A>(value: A): (Anonymous function)
  • Create a function that always returns a given value

    Type parameters

    • A

    Parameters

    • value: A

      :: a

    Returns (Anonymous function)

    (...* -> a)

Const curry

  • curry<F>(f: F): Curry<F>

Const curryObj

Const flip

  • flip<T>(fn: T): Flip<T>

Const id

  • id<A>(value: A): A

Const memoize

  • memoize<F>(f: F): F

Const noOp

  • noOp(): void

Const pipe2

  • pipe2<A, B, C>(f: Arity1<A, B>, g: Arity1<B, C>): (Anonymous function)

pipeline

uncurry

Generated using TypeDoc