/** * Separate elements based on a predicate that also exposes the index of the * element. * * @tsplus static Chunk.Aspects partitionWithIndex * @tsplus pipeable Chunk partitionWithIndex */ export function partitionWithIndex(f: PredicateWithIndex) { return (self: Chunk): readonly [Chunk, Chunk] => { const left: Array = [] const right: Array = [] for (let i = 0; i < self.length; i++) { const a = self.unsafeGet(i)! if (f(i, a)) { right.push(a) } else { left.push(a) } } return [Chunk.from(left), Chunk.from(right)] } }