Package: effect
Module: Array
Splits an iterable using a Filter into failures and successes.
When to use
Use to partition an iterable by evaluating each element with a
Result-returning filter and keeping both failure and success values.
Details
Returns [excluded, satisfying]. The filter receives (element, index).
Example (Partitioning with a filter)
import { Array, Result } from "effect"
console.log(Array.partition([1, -2, 3], (n, i) =>
n > 0 ? Result.succeed(n + i) : Result.fail(`negative:${n}`)
))
// [["negative:-2"], [1, 5]]
See
filter — keep only matching elementsfilterMap for discarding failuresseparate — split an iterable of Result valuesSignature
declare const partition: { <A, Pass, Fail>(f: (input: NoInfer<A>, i: number) => Result.Result<Pass, Fail>): (self: Iterable<A>) => [excluded: Array<Fail>, satisfying: Array<Pass>]; <A, Pass, Fail>(self: Iterable<A>, f: (input: A, i: number) => Result.Result<Pass, Fail>): [excluded: Array<Fail>, satisfying: Array<Pass>]; }
Since v2.0.0