Options
All
  • Public
  • Public/Protected
  • All
Menu

@bhc/ts-tools

Index

Type aliases

Drop<T, Count, Droped>: Droped extends { length: infer U } ? U extends Count ? T : Drop<Tail<T>, Count, [...Droped, Head<T>]> : never

Send back the type of the tuple with Count element droped from the front.

author

Valentin Vivier

Type parameters

  • T: unknown[]

    Any kind of tuple or array.

  • Count: number

    Number of element to drop from the front.

  • Droped: unknown[] = []

    Internal use only. Should be left by default.

EffectfulProgram<A, B>: (_1: A) => Effect<B>

Type parameters

  • A

  • B

Type declaration

F<A, B>: (...args: A[]) => B

Type parameters

  • A

  • B

Type declaration

    • (...args: A[]): B
    • Parameters

      • Rest ...args: A[]

      Returns B

FlipF<T>: T extends (...a: infer Params) => infer R ? (...a: FlipT<Params>) => R : never

Send back a function type with fliped params.

author

Valentin Vivier

Type parameters

  • T

    Any kind of function.

FlipT<T>: T extends [] ? [] : [...FlipT<Tail<T>>, Head<T>]

Send back the type of the fliped tuple or array.

author

Valentin Vivier

Type parameters

  • T: unknown[]

    Any kind of tuple or array.

Func: (...args: unknown[]) => unknown

Type declaration

    • (...args: unknown[]): unknown
    • Parameters

      • Rest ...args: unknown[]

      Returns unknown

Head<T>: T extends [head: infer U, tail: unknown[]] ? U : never

Send back the type of the first element of the tuple or array.

author

Valentin Vivier

Type parameters

  • T: unknown[]

    Any kind of tuple or array.

Identity<A>: A

Type parameters

  • A

Init<T>: T extends [...infer I, unknown] ? I : never

Send back the types of the tuple or array elements but last.

author

Valentin Vivier

Type parameters

  • T: unknown[]

    Any kind of tuple or array.

Last<T>: T extends [...unknown[], infer L] ? L : T[0]

Send back the type of the last element of the tuple or array.

author

Valentin Vivier

Type parameters

  • T: unknown[]

    Any kind of tuple or array.

Lens<T, U>: { get: any; set: any }

Lens type for hard typing & "type safety".

author

Valentin Vivier

Type parameters

  • T

    Type of the main object.

  • U

    Type of the field targeted by the lens.

Type declaration

  • get:function
    • get(arg0: T): U
  • set:function
    • set(arg0: U, arg1: T): T
Program<A, B>: (_1: A) => B

Type parameters

  • A

  • B

Type declaration

    • (_1: A): B
    • Parameters

      • _1: A

      Returns B

PureFunction<A>: (_1: A) => A

Type parameters

  • A

Type declaration

    • (_1: A): A
    • Parameters

      • _1: A

      Returns A

Tail<T>: T extends [head: unknown, tail: infer U] ? U : never

Send back the types of the tuple or array without his first element.

author

Valentin Vivier

Type parameters

  • T: unknown[]

    Any kind of tuple or array.

Void<A>: (...args: A[]) => void

Type parameters

  • A

Type declaration

    • (...args: A[]): void
    • Parameters

      • Rest ...args: A[]

      Returns void

recordType<A>: A

Type parameters

Functions

  • always<A>(value: A): () => A
  • Type parameters

    • A

    Parameters

    • value: A

    Returns () => A

      • (): A
      • Returns A

  • compose<A, R>(...fns: [(a: unknown) => R, ...Func[], (...a: A[]) => unknown]): F<A, R>
  • Compose a reverse pipe.

    author

    Valentin Vivier

    Type parameters

    • A

    • R

    Parameters

    • Rest ...fns: [(a: unknown) => R, ...Func[], (...a: A[]) => unknown]

      Functions to compose.

    Returns F<A, R>

    Composed function.

  • copy<T>(obj: T): T
  • This function create a deep copy of any variable, with any nesting construction. May not support every type in the book. To test out. Inspired by https://stackoverflow.com/a/28152032.

    author

    Valentin Vivier

    Type parameters

    • T

    Parameters

    • obj: T

    Returns T

    Copied object.

  • curry<T, U, R>(func: (...args: [...T[], ...U[]]) => R, ...args: T): (...trail: U) => R
  • Curry a function.

    author

    Valentin Vivier

    Type parameters

    • T: unknown[]

    • U: unknown[]

    • R

    Parameters

    • func: (...args: [...T[], ...U[]]) => R

      Function to curry.

        • (...args: [...T[], ...U[]]): R
        • Parameters

          • Rest ...args: [...T[], ...U[]]

          Returns R

    • Rest ...args: T

      Argument to pine to curried function.

    Returns (...trail: U) => R

    Curried function.

      • (...trail: U): R
      • Parameters

        • Rest ...trail: U

        Returns R

  • emit(s: string | Error): never
  • eql<T, U>(objLeft: T, objRight: U): boolean
  • This function deep compare anything.

    author

    Valentin Vivier

    Type parameters

    • T

    • U

    Parameters

    • objLeft: T

      First things to compare.

    • objRight: U

      Second things to compare.

    Returns boolean

    True if arrays match, false otherwise.

  • flip<T, R>(fn: (...args: [...T[]]) => R): (...a: FlipT<T>) => R
  • Flip arguments order of a function.

    author

    Valentin Vivier

    Type parameters

    • T: unknown[]

    • R

    Parameters

    • fn: (...args: [...T[]]) => R

      Function to flip.

        • (...args: [...T[]]): R
        • Parameters

          • Rest ...args: [...T[]]

          Returns R

    Returns (...a: FlipT<T>) => R

    Fliped function.

      • Parameters

        Returns R

  • flipt<T>(args: [...T[]]): FlipT<T>
  • Flip tuple.

    author

    Valentin Vivier

    Type parameters

    • T: unknown[]

    Parameters

    • args: [...T[]]

      Tuple to flip.

    Returns FlipT<T>

    Fliped function.

  • fmap<A, B, EA, EB>(f: (a: A) => B, a: EA): EB
  • fmap<A, B, EA, EB>(f: (a: A) => B, a: EA[]): EB[]
  • Type parameters

    Parameters

    • f: (a: A) => B
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    • a: EA

    Returns EB

  • Type parameters

    Parameters

    • f: (a: A) => B
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    • a: EA[]

    Returns EB[]

  • forward<A, FS>(forward: A, ...fs: FS): ReturnType<Last<FS>>
  • Type parameters

    • A

    • FS: ((a: A) => unknown)[]

    Parameters

    • forward: A
    • Rest ...fs: FS

    Returns ReturnType<Last<FS>>

  • forwardIf<A, B>(forward: A, pred: (a: A) => boolean, f: (a: A) => B): Maybe<B>
  • Type parameters

    • A

    • B

    Parameters

    • forward: A
    • pred: (a: A) => boolean
        • (a: A): boolean
        • Parameters

          • a: A

          Returns boolean

    • f: (a: A) => B
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    Returns Maybe<B>

  • forwardIfAsync<A, B>(forward: A, pred: (a: A) => Promise<boolean>, f: (a: A) => B): Promise<Maybe<B>>
  • Type parameters

    • A

    • B

    Parameters

    • forward: A
    • pred: (a: A) => Promise<boolean>
        • (a: A): Promise<boolean>
        • Parameters

          • a: A

          Returns Promise<boolean>

    • f: (a: A) => B
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    Returns Promise<Maybe<B>>

  • forwardTern<A, B, C>(forward: A, pred: (a: A) => boolean, truthy: (a: A) => B, falsy: (a: A) => C): Either<C, B>
  • Type parameters

    • A

    • B

    • C

    Parameters

    • forward: A
    • pred: (a: A) => boolean
        • (a: A): boolean
        • Parameters

          • a: A

          Returns boolean

    • truthy: (a: A) => B
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    • falsy: (a: A) => C
        • (a: A): C
        • Parameters

          • a: A

          Returns C

    Returns Either<C, B>

  • forwardTernAsync<A, B, C>(forward: A, pred: (a: A) => Promise<boolean>, truthy: (a: A) => B, falsy: (a: A) => C): Promise<Either<C, B>>
  • Type parameters

    • A

    • B

    • C

    Parameters

    • forward: A
    • pred: (a: A) => Promise<boolean>
        • (a: A): Promise<boolean>
        • Parameters

          • a: A

          Returns Promise<boolean>

    • truthy: (a: A) => B
        • (a: A): B
        • Parameters

          • a: A

          Returns B

    • falsy: (a: A) => C
        • (a: A): C
        • Parameters

          • a: A

          Returns C

    Returns Promise<Either<C, B>>

  • head<T>(tuple: [...T[]]): Head<T>
  • Send back a copy of the first element of the tuple or array.

    author

    Valentin Vivier

    Type parameters

    • T: unknown[]

      Any kind of tuple or array.

    Parameters

    • tuple: [...T[]]

      Tuple or array to get head from.

    Returns Head<T>

    First element of the tuple or array.

  • init<T>(tuple: [...T[]]): Init<T>
  • Drop the last element of the tuple or array.

    author

    Valentin Vivier

    Type parameters

    • T: unknown[]

    Parameters

    • tuple: [...T[]]

      Tuple or array to cut.

    Returns Init<T>

    Copy of the original tuple or array minus his last element.

  • last<T>(arg: T): Last<T>
  • Get the last element of a tuple or array.

    author

    Valentin Vivier

    Type parameters

    • T: unknown[]

      Any kind of tuple or array.

    Parameters

    • arg: T

    Returns Last<T>

    Last element.

  • lens<T, U>(getter: (_1: T) => U, setter: (_1: U, _2: T) => T): Lens<T, U>
  • Lens default 'constructor'.

    author

    Valentin Vivier

    Type parameters

    • T

      Type of the main object.

    • U

      Type of the field targeted by the lens.

    Parameters

    • getter: (_1: T) => U

      Getter function.

        • (_1: T): U
        • Parameters

          • _1: T

          Returns U

    • setter: (_1: U, _2: T) => T

      Setter function.

        • (_1: U, _2: T): T
        • Parameters

          • _1: U
          • _2: T

          Returns T

    Returns Lens<T, U>

    Lens contructed with given parameters.

  • lensFrom<T, U>(path: string | (string | number)[], split?: string): Lens<T, U>
  • Lens 'kind of advance' contructor. Construct the lens from a given path.

    author

    Valentin Vivier

    Type parameters

    • T

      Type of the main object.

    • U

      Type of the field targeted by the lens.

    Parameters

    • path: string | (string | number)[]

      Path of the target. Can be a string, each subfield separated by a separator. Or a tuple of string and number representing subfield and indexes.

    • split: string = '.'

      If path is a string, the separator will be call with string.split.

    Returns Lens<T, U>

    Lens contructed with given parameters.

  • lockFor(cond: () => boolean, timeout?: number, maxRecuse?: number): Promise<void>
  • This function will regularly check for conditional function and maybe release the lock.

    author

    Valentin Vivier

    Parameters

    • cond: () => boolean

      Conditinal function.

        • (): boolean
        • Returns boolean

    • timeout: number = 50

      Time in milliseconds between each check.

    • maxRecuse: number = null

      Maximum number of check before force liberating with throw.

    Returns Promise<void>

    A void promise to release the await.

  • memoise<A, B>(f: (...args: A) => B): (...args: A) => B
  • Type parameters

    • A: unknown[]

    • B

    Parameters

    • f: (...args: A) => B
        • (...args: A): B
        • Parameters

          • Rest ...args: A

          Returns B

    Returns (...args: A) => B

      • (...args: A): B
      • Parameters

        • Rest ...args: A

        Returns B

  • observe<T>(obs: Observable<T>, timeout?: number, enforce?: boolean): AsyncIterableIterator<T>
  • Generator function to an Observable. Yielding on change made. Multiple change can occurs without the function noticing if happening between register.

    author

    Valentin Vivier

    Type parameters

    • T

      Type holded by the observer.

    Parameters

    • obs: Observable<T>

      Observer to await change on.

    • timeout: number = 0

      Time before timeout is triggered. If 0, the function will not timeout. Default to 0.

    • enforce: boolean = false

      If true, timeout will throw with Error("Observable: Timeout on change"). If false, timeout will resolve with null. Default to false.

    Returns AsyncIterableIterator<T>

  • pipe<A, R>(...fns: [(...a: A[]) => unknown, ...Func[], (a: unknown) => R]): F<A, R>
  • Compose a pipe.

    author

    Valentin Vivier

    Type parameters

    • A

    • R

    Parameters

    • Rest ...fns: [(...a: A[]) => unknown, ...Func[], (a: unknown) => R]

      Functions to pipe.

    Returns F<A, R>

    Piped function.

  • pipeAsync<A, R>(...fns: [(...a: A[]) => unknown, ...Func[], (a: unknown) => R]): F<A, R>
  • Type parameters

    • A

    • R

    Parameters

    • Rest ...fns: [(...a: A[]) => unknown, ...Func[], (a: unknown) => R]

    Returns F<A, R>

  • pipeEffect<A, R>(...fns: [(...a: A[]) => unknown, ...Func[], (a: unknown) => R]): F<A, R>
  • Type parameters

    • A

    • R

    Parameters

    • Rest ...fns: [(...a: A[]) => unknown, ...Func[], (a: unknown) => R]

    Returns F<A, R>

  • pipeEffectAsync<A, R>(...fns: [(...a: A[]) => unknown, ...Func[], (a: unknown) => R]): F<A, R>
  • Type parameters

    • A

    • R

    Parameters

    • Rest ...fns: [(...a: A[]) => unknown, ...Func[], (a: unknown) => R]

    Returns F<A, R>

  • rcurry<T, U, R>(func: (...args: [...U[], ...T[]]) => R, ...args: [...T[]]): (...a: FlipT<U>) => R
  • Reverse curry a function.

    author

    Valentin Vivier

    Type parameters

    • T: unknown[]

    • U: unknown[]

    • R

    Parameters

    • func: (...args: [...U[], ...T[]]) => R

      Function to curry.

        • (...args: [...U[], ...T[]]): R
        • Parameters

          • Rest ...args: [...U[], ...T[]]

          Returns R

    • Rest ...args: [...T[]]

      Argument to pine to curried function.

    Returns (...a: FlipT<U>) => R

    Curried function.

      • Parameters

        Returns R

  • set<T, U>(_lens: Lens<T, U>, value: U, obj: T): T
  • Create a copy of the object and apply the lens on it to change the targeted value. Doesn't mutate.

    author

    Valentin Vivier

    Type parameters

    • T

      Type of the main object.

    • U

      Type of the field targeted by the lens.

    Parameters

    • _lens: Lens<T, U>

      Lens to use.

    • value: U

      Value to set the target to.

    • obj: T

      Object to apply the lens on.

    Returns T

    The new object created with its targeted field value changed.

  • show<T>(a: T): T
  • showf<A, B>(f: (...a: A) => B): (...a: A) => B
  • Type parameters

    • A: unknown[]

    • B

    Parameters

    • f: (...a: A) => B
        • (...a: A): B
        • Parameters

          • Rest ...a: A

          Returns B

    Returns (...a: A) => B

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

        • Rest ...a: A

        Returns B

  • showfAsync<A, B>(f: (...a: A) => Promise<B>): (...a: A) => Promise<B>
  • Type parameters

    • A: unknown[]

    • B

    Parameters

    • f: (...a: A) => Promise<B>
        • (...a: A): Promise<B>
        • Parameters

          • Rest ...a: A

          Returns Promise<B>

    Returns (...a: A) => Promise<B>

      • (...a: A): Promise<B>
      • Parameters

        • Rest ...a: A

        Returns Promise<B>

  • sleep(timeout: number): Promise<void>
  • This function will returned a promise lock for timeout milliseconds.

    author

    Valentin Vivier

    Parameters

    • timeout: number

      Time in milliseconds before releaseing the lock.

    Returns Promise<void>

    A void promise to release the await.

  • tail<T>(tuple: [...T[]]): Tail<T>
  • Send back a copy of a tuple or array without his first element.

    author

    Valentin Vivier

    Type parameters

    • T: unknown[]

      Any kind of tuple or array.

    Parameters

    • tuple: [...T[]]

      Tuple or array to cut.

    Returns Tail<T>

    Copy of the original tuple or array minus his first element.

  • tobe<T>(obs: Observable<T> | AsyncIterableIterator<T>, cond: (arg1: T) => boolean): Promise<void>
  • This function will create a silent lock on an Observable, releasing only when the conditional function return true.

    author

    Valentin Vivier

    Type parameters

    • T

      Type holded by the observer.

    Parameters

    • obs: Observable<T> | AsyncIterableIterator<T>

      Either an Observable or an AsyncIterableIterator mainly created from with observe.

    • cond: (arg1: T) => boolean

      Conditinal function.

        • (arg1: T): boolean
        • Parameters

          • arg1: T

          Returns boolean

    Returns Promise<void>

    A void promise to release the await.

  • view<T, U>(_lens: Lens<T, U>, obj: T): U
  • Return the value of the target field by the lens from the object.

    author

    Valentin Vivier

    Type parameters

    • T

      Type of the main object.

    • U

      Type of the field targeted by the lens.

    Parameters

    • _lens: Lens<T, U>

      Lens to use.

    • obj: T

      Object to apply the lens on.

    Returns U

    The targeted value.

Generated using TypeDoc