UNPKG

wellcrafted

Version:

Delightful TypeScript patterns for elegant, type-safe applications

30 lines (28 loc) 852 B
import { isOk } from "./result-C_ph_izC.js"; //#region src/result/utils.ts /** * Partitions an array of Result objects into two separate arrays based on their status. * * @template T - The success type * @template E - The error type * @param results - An array of Result objects to partition * @returns An object containing two arrays: * - `oks`: Array of successful Result objects (Ok<T>[]) * - `errs`: Array of error Result objects (Err<E>[]) * * @example * const results = [Ok(1), Err("error"), Ok(2)]; * const { oks, errs } = partitionResults(results); * // oks = [Ok(1), Ok(2)] * // errs = [Err("error")] */ function partitionResults(results) { return { oks: [], errs: [], ...Object.groupBy(results, (result) => isOk(result) ? "oks" : "errs") }; } //#endregion export { partitionResults }; //# sourceMappingURL=result-pV2mfn0W.js.map