Options
All
  • Public
  • Public/Protected
  • All
Menu

@tsfun/array — Reference

Index

Variables

Const init

init: <Item>(array: readonly Item[]) => Item[] = initStrict

Get all but last items of an array

param

Input array

returns

All but last items of array

Type declaration

    • <Item>(array: readonly Item[]): Item[]
    • Type parameters

      • Item

      Parameters

      • array: readonly Item[]

      Returns Item[]

Const partitionPredicate

partitionPredicate: <Type, Subtype>(iterable: Iterable<Type>, predicate: (item: Type) => item is Subtype) => [Subtype[], Type[]] = partition as any

Like partition but with type predicate

Type declaration

    • <Type, Subtype>(iterable: Iterable<Type>, predicate: (item: Type) => item is Subtype): [Subtype[], Type[]]
    • Classify a set of items into 2 groups

      Type parameters

      • Type

      • Subtype: Type

      Parameters

      • iterable: Iterable<Type>

        List of items

      • predicate: (item: Type) => item is Subtype

        Function that classifies item

          • (item: Type): item is Subtype
          • Parameters

            • item: Type

            Returns item is Subtype

      Returns [Subtype[], Type[]]

      A tuple of 2 item groups

      • First group includes items that predicate returns true
      • Second group includes items that predicate returns false

Const tailStrict

tailStrict: <Tail>(array: readonly [any]) => Tail = tail as any

Get all but first items of an array

param

Input array

returns

All but first items of array

Type declaration

    • <Tail>(array: readonly [any]): Tail
    • Type parameters

      • Tail: any[]

      Parameters

      • array: readonly [any]

      Returns Tail

Functions

Const head

  • head<Head>(array: readonly [Head, any]): Head
  • Get first item of an array

    Type parameters

    • Head

    Parameters

    • array: readonly [Head, any]

      Array to get first item from

    Returns Head

    First item of array

Const headOr

  • headOr<Item, Default>(array: readonly Item[], def: Default): Item | Default
  • Get first item of an array

    Type parameters

    • Item

    • Default

    Parameters

    • array: readonly Item[]

      Array to get first item from

    • def: Default

      Value to return should array is found empty

    Returns Item | Default

    First item of array if it's not empty, or def otherwise

Const headOrUndefined

  • headOrUndefined<Item>(array: readonly Item[]): any
  • Get first item of an array

    Type parameters

    • Item

    Parameters

    • array: readonly Item[]

      Array to get first item from

    Returns any

    First item of array if it's not empty, or undefined otherwise

Const initStrict

  • initStrict<Init>(array: readonly [any]): Init
  • Get all but last items of an array

    Type parameters

    • Init: any[]

    Parameters

    • array: readonly [any]

      Input array

    Returns Init

    All but last items of array

Const last

  • last<Init, Last>(array: readonly [Last]): Last
  • Get last item of an array

    Type parameters

    • Init: any[]

    • Last

    Parameters

    • array: readonly [Last]

      Array to get last item from

    Returns Last

    Last item of array

Const lastOr

  • lastOr<Item, Default>(array: readonly Item[], def: Default): Item | Default
  • Get last item of an array

    Type parameters

    • Item

    • Default

    Parameters

    • array: readonly Item[]

      Array to get last item from

    • def: Default

      Value to return should array is found empty

    Returns Item | Default

    Last item of array if it's not empty, or def otherwise

Const lastOrUndefined

  • lastOrUndefined<Item>(array: readonly Item[]): any
  • Get last item of an array

    Type parameters

    • Item

    Parameters

    • array: readonly Item[]

      Array to get last item from

    Returns any

    Last item of array if it's not empty, or undefined otherwise

partition

  • partition<Item>(iterable: Iterable<Item>, predicate: (item: Item) => boolean): [Item[], Item[]]
  • Classify a set of items into 2 groups

    Type parameters

    • Item

    Parameters

    • iterable: Iterable<Item>

      List of items

    • predicate: (item: Item) => boolean

      Function that classifies item

        • (item: Item): boolean
        • Parameters

          • item: Item

          Returns boolean

    Returns [Item[], Item[]]

    A tuple of 2 item groups

    • First group includes items that predicate returns true
    • Second group includes items that predicate returns false

Const range

  • range(count: number): number[]
  • Create an array of ascending integers

    Parameters

    • count: number

      Number of integers

    Returns number[]

    An array of integers from 0 to under count

Const splitAt

  • splitAt<Item>(array: readonly Item[], index: number): [Item[], Item[]]
  • Split an array into 2 parts

    Type parameters

    • Item

    Parameters

    • array: readonly Item[]

      Array to split

    • index: number

      Where to split

    Returns [Item[], Item[]]

    A tuple of two parts

Const tail

  • tail<Item>(array: readonly Item[]): Item[]
  • Get all but first items of an array

    Type parameters

    • Item

    Parameters

    • array: readonly Item[]

      Input array

    Returns Item[]

    All but first items of array

zip

  • zip<A, B>(a: readonly A[], b: readonly B[]): [A, B][]
  • Create a list of pairs from two lists

    Type parameters

    • A

    • B

    Parameters

    • a: readonly A[]

      Array of left items

    • b: readonly B[]

      Array of right items

    Returns [A, B][]

    An array of pairs

Generated using TypeDoc