/** * Separate elements based on a map function that also exposes the index. * * @tsplus static ImmutableArray.Aspects partitionMapWithIndex * @tsplus pipeable ImmutableArray partitionMapWithIndex */ export function partitionMapWithIndex(f: (i: number, a: A) => Either) { return (self: ImmutableArray): readonly [ImmutableArray, ImmutableArray] => { const left: Array = [] const right: Array = [] for (let i = 0; i < self.array.length; i = i + 1) { const e = f(i, self.array[i]!) if (e._tag === "Left") { left.push(e.left) } else { right.push(e.right) } } return [new ImmutableArray(left), new ImmutableArray(right)] } }