common-stuff
    Preparing search index...

    Function partition

    • Splits an iterable structure into two — [matching, rest] — by a predicate.

      Both halves preserve the input container type. With an async predicate the result is wrapped in a Promise.

      Type Parameters

      • V

      Parameters

      • input: V[]
      • predicate: (value: V, index: number) => Promise<boolean>

      Returns Promise<[V[], V[]]>

      partition([1, 2, 3, 4], v => v % 2 === 0)
      // [[2, 4], [1, 3]]

      partition({ a: 1, b: 2 }, ([, v]) => v > 1)
      // [{ b: 2 }, { a: 1 }]
    • Splits an iterable structure into two — [matching, rest] — by a predicate.

      Both halves preserve the input container type. With an async predicate the result is wrapped in a Promise.

      Type Parameters

      • V

      Parameters

      • input: V[]
      • predicate: (value: V, index: number) => boolean

      Returns [V[], V[]]

      partition([1, 2, 3, 4], v => v % 2 === 0)
      // [[2, 4], [1, 3]]

      partition({ a: 1, b: 2 }, ([, v]) => v > 1)
      // [{ b: 2 }, { a: 1 }]
    • Splits an iterable structure into two — [matching, rest] — by a predicate.

      Both halves preserve the input container type. With an async predicate the result is wrapped in a Promise.

      Type Parameters

      • K
      • V

      Parameters

      • input: Map<K, V>
      • predicate: (value: [K, V], index: number) => Promise<boolean>

      Returns Promise<[Map<K, V>, Map<K, V>]>

      partition([1, 2, 3, 4], v => v % 2 === 0)
      // [[2, 4], [1, 3]]

      partition({ a: 1, b: 2 }, ([, v]) => v > 1)
      // [{ b: 2 }, { a: 1 }]
    • Splits an iterable structure into two — [matching, rest] — by a predicate.

      Both halves preserve the input container type. With an async predicate the result is wrapped in a Promise.

      Type Parameters

      • K
      • V

      Parameters

      • input: Map<K, V>
      • predicate: (value: [K, V], index: number) => boolean

      Returns [Map<K, V>, Map<K, V>]

      partition([1, 2, 3, 4], v => v % 2 === 0)
      // [[2, 4], [1, 3]]

      partition({ a: 1, b: 2 }, ([, v]) => v > 1)
      // [{ b: 2 }, { a: 1 }]
    • Splits an iterable structure into two — [matching, rest] — by a predicate.

      Both halves preserve the input container type. With an async predicate the result is wrapped in a Promise.

      Type Parameters

      • T

      Parameters

      • input: Set<T>
      • predicate: (value: T, index: number) => Promise<boolean>

      Returns Promise<[Set<T>, Set<T>]>

      partition([1, 2, 3, 4], v => v % 2 === 0)
      // [[2, 4], [1, 3]]

      partition({ a: 1, b: 2 }, ([, v]) => v > 1)
      // [{ b: 2 }, { a: 1 }]
    • Splits an iterable structure into two — [matching, rest] — by a predicate.

      Both halves preserve the input container type. With an async predicate the result is wrapped in a Promise.

      Type Parameters

      • T

      Parameters

      • input: Set<T>
      • predicate: (value: T, index: number) => boolean

      Returns [Set<T>, Set<T>]

      partition([1, 2, 3, 4], v => v % 2 === 0)
      // [[2, 4], [1, 3]]

      partition({ a: 1, b: 2 }, ([, v]) => v > 1)
      // [{ b: 2 }, { a: 1 }]
    • Splits an iterable structure into two — [matching, rest] — by a predicate.

      Both halves preserve the input container type. With an async predicate the result is wrapped in a Promise.

      Type Parameters

      • T

      Parameters

      • input: AsyncIterable<T>
      • predicate: (value: T, index: number) => boolean | Promise<boolean>

      Returns Promise<[T[], T[]]>

      partition([1, 2, 3, 4], v => v % 2 === 0)
      // [[2, 4], [1, 3]]

      partition({ a: 1, b: 2 }, ([, v]) => v > 1)
      // [{ b: 2 }, { a: 1 }]
    • Splits an iterable structure into two — [matching, rest] — by a predicate.

      Both halves preserve the input container type. With an async predicate the result is wrapped in a Promise.

      Type Parameters

      • T

      Parameters

      • input: Iterable<T>
      • predicate: (value: T, index: number) => Promise<boolean>

      Returns Promise<[T[], T[]]>

      partition([1, 2, 3, 4], v => v % 2 === 0)
      // [[2, 4], [1, 3]]

      partition({ a: 1, b: 2 }, ([, v]) => v > 1)
      // [{ b: 2 }, { a: 1 }]
    • Splits an iterable structure into two — [matching, rest] — by a predicate.

      Both halves preserve the input container type. With an async predicate the result is wrapped in a Promise.

      Type Parameters

      • T

      Parameters

      • input: Iterable<T>
      • predicate: (value: T, index: number) => boolean

      Returns [T[], T[]]

      partition([1, 2, 3, 4], v => v % 2 === 0)
      // [[2, 4], [1, 3]]

      partition({ a: 1, b: 2 }, ([, v]) => v > 1)
      // [{ b: 2 }, { a: 1 }]
    • Splits an iterable structure into two — [matching, rest] — by a predicate.

      Both halves preserve the input container type. With an async predicate the result is wrapped in a Promise.

      Type Parameters

      • K extends PropertyKey
      • V

      Parameters

      • input: Record<K, V>
      • predicate: (value: [K, V], index: number) => Promise<boolean>

      Returns Promise<[Record<K, V>, Record<K, V>]>

      partition([1, 2, 3, 4], v => v % 2 === 0)
      // [[2, 4], [1, 3]]

      partition({ a: 1, b: 2 }, ([, v]) => v > 1)
      // [{ b: 2 }, { a: 1 }]
    • Splits an iterable structure into two — [matching, rest] — by a predicate.

      Both halves preserve the input container type. With an async predicate the result is wrapped in a Promise.

      Type Parameters

      • K extends PropertyKey
      • V

      Parameters

      • input: Record<K, V>
      • predicate: (value: [K, V], index: number) => boolean

      Returns [Record<K, V>, Record<K, V>]

      partition([1, 2, 3, 4], v => v % 2 === 0)
      // [[2, 4], [1, 3]]

      partition({ a: 1, b: 2 }, ([, v]) => v > 1)
      // [{ b: 2 }, { a: 1 }]