Hyperlinkv0.8.0-beta.28

Array

Array.splitWhereconsteffect/Array.ts:2770
<A>(predicate: (a: NoInfer<A>, i: number) => boolean): (
  self: Iterable<A>
) => [beforeMatch: Array<A>, fromMatch: Array<A>]
<A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [
  beforeMatch: Array<A>,
  fromMatch: Array<A>
]

Splits an iterable at the first element matching the predicate. The matching element is included in the second array.

When to use

Use when you need to split an array at the first element that marks a condition boundary.

Example (Splitting at a condition)

import { Array } from "effect"

console.log(Array.splitWhere([1, 2, 3, 4, 5], (n) => n > 3)) // [[1, 2, 3], [4, 5]]
splittingspansplitAt
Source effect/Array.ts:277010 lines
export const splitWhere: {
  <A>(
    predicate: (a: NoInfer<A>, i: number) => boolean
  ): (self: Iterable<A>) => [beforeMatch: Array<A>, fromMatch: Array<A>]
  <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [beforeMatch: Array<A>, fromMatch: Array<A>]
} = dual(
  2,
  <A>(self: Iterable<A>, predicate: (a: A, i: number) => boolean): [beforeMatch: Array<A>, fromMatch: Array<A>] =>
    span(self, (a: A, i: number) => !predicate(a, i))
)