Options
All
  • Public
  • Public/Protected
  • All
Menu

Index

Functions

clearResults

  • clearResults(resultContainer: HTMLElement): void
  • Parameters

    • resultContainer: HTMLElement

    Returns void

deepCopy

  • deepCopy<T>(a: T): T
  • Creates a deep copy of an object. This means that fields of the object are also recursively copied, so the result is entirely independent of the original.

    Type parameters

    • T

    Parameters

    • a: T

      Object to copy

    Returns T

    Copy of a

extractOption

  • extractOption<T>(a: Option<T>[]): Option<T[]>
  • Turn an array of Options into an Option of an array. If any Nones exist in the array, returns None. Otherwise, returns Some of the entire array of unwrapped elements.

    Type parameters

    • T

    Parameters

    • a: Option<T>[]

    Returns Option<T[]>

extractResult

  • extractResult<T, E>(a: Result<T, E>[]): Result<T[], E>
  • Turn an array of Results into a Result of an array. If any Errs exist in the array, returns one of those Errs. Otherwise, returns Ok of the entire array of unwrapped elements.

    Type parameters

    • T

    • E

    Parameters

    • a: Result<T, E>[]

    Returns Result<T[], E>

flatten

  • flatten<T>(a: T[][]): T[]
  • Flatten a list of lists into a single-depth list

    Type parameters

    • T

    Parameters

    • a: T[][]

      List of lists

    Returns T[]

    Flattened single-depth list

goRes

  • goRes<T, U>(a: Result<T, U>, errorMessage?: string): [T, null] | [null, string]
  • Due to TypeScript's lack of something like Rust's ? operator, working with Results can be cumbersome. This function converts Results into something like Go's error handling paradigm, which is at least more concise and type safe than a naive TypeScript-Result paradigm.

    Example

    const resultRandom: Result<number, string> = maybeRandom();
    
    const randErr = goRes(resultRandom, "could not get random number");
    if (randErr[1] !== null) { return Err(randErr[1]); }
    const rand: number = randErr[0];
    

    or preferably, simply

    const randErr = goRes(maybeRandom(), "could not get random number");
    if (randErr[1] !== null) { return Err(randErr[1]); }
    const rand = randErr[0];
    

    Type parameters

    • T

    • U

    Parameters

    • a: Result<T, U>

      Result to Go-ify

    • errorMessage: string = ""

      Error message prefix to use in case of Err

    Returns [T, null] | [null, string]

    If a is Ok(something), returns [something, null]. If a is Err(error), returns [null, errorMessage + error].

has

  • has<T>(object: T, key: PropertyKey): key is keyof T
  • Determine if a key is present in an object. Allows TypeScript to permit indexing into objects.

    Example:

    const a = { hello: "world" };
    if (has(a, "hello")) {
        console.log(a["hello"]); // No errors!
    }
    

    Type parameters

    • T

    Parameters

    • object: T
    • key: PropertyKey

    Returns key is keyof T

removeChildren

  • removeChildren(element: HTMLElement): void
  • Removes all children of an element.

    Parameters

    • element: HTMLElement

    Returns void

t

  • t<T>(...a: T): T
  • Explicitly create a tuple. Same as doing [x, y, ...], but can return a tuple type instead of array.

    Type parameters

    • T: unknown[]

    Parameters

    • Rest ...a: T

      Elements of the tuple

    Returns T

    Tuple of as

updateWithResults

zip

  • zip<T, U>(a: T[], b: U[]): [T, U][]
  • Merges two arrays into a single array of pairs. Takes the length of the shorter array and discards the elements of the longer one above that length.

    Type parameters

    • T

    • U

    Parameters

    • a: T[]

      First array to merge

    • b: U[]

      Second array to merge

    Returns [T, U][]

    Array of pairs of corresponding elements of a and b

zipInto

  • zipInto<T, U, V>(a: [T, U][], b: V[]): [T, U, V][]
  • zipInto<T, U, V, W>(a: [T, U, V][], b: W[]): [T, U, V, W][]
  • Merges an array into an existing array of pairs to create an array of triplets. Takes the length of the shorter array and discards the elements of the longer one above that length.

    Type parameters

    • T

    • U

    • V

    Parameters

    • a: [T, U][]

      Array of pairs

    • b: V[]

      Array to merge in

    Returns [T, U, V][]

    Single array of triplets

  • Merges an array into an existing array of triplets to create an array of quadruplets. Takes the length of the shorter array and discards the elements of the longer one above that length.

    Type parameters

    • T

    • U

    • V

    • W

    Parameters

    • a: [T, U, V][]

      Array of triplets

    • b: W[]

      Array to merge in

    Returns [T, U, V, W][]

    Single array of quadruplets

Generated using TypeDoc