/** * Utilities for iterable objects. Use this module by importing from from * `@sirpepe/shed/iterable`. */ /** * Groups the elements of an iterable in an array by a key and organizes the * arrays in a map. The map's keys are generated by a selector which can either * be a function or a key for any property on the elements. The selector * function (if provided) is invoked with one argument (the current value). * * Examples: * * ```typescript * const input = [ * { x: 0, y: "a" }, * { x: 1, y: "b" }, * { x: 2, y: "a" }, * { x: 3, y: "c" }, * { x: 4, y: "b" }, * ]; * * const fromProperty = groupBy(input, "y"); * // returns: Map { * // "a" => [{ x: 0, y: "a" }, { x: 2, y: "a" }], * // "b" => [{ x: 1, y: "b" }, { x: 4, y: "b" }], * // "c" => [{ x: 3, y: "c" }], * // } * * const fromFunction = groupBy(input, (value) => value.y.charCodeAt(0) % 2) * // returns: Map { * // 1 => [{ x: 0, y: "a" }, { x: 2, y: "a" }, { x: 3, y: "c" }], * // 0 => [{ x: 1, y: "b" }, { x: 4, y: "b" }, { x: 5, y: "b" }], * // } * ``` */ export declare function groupBy(input: Iterable, selector: Key): Map; export declare function groupBy(input: Iterable, selector: (element: T, index: number) => Key): Map; /** * Organizes the elements of an iterable in a map. The map's keys are generated * by a selector which can either be a function or a key for any property on the * elements. The selector function (if provided) is invoked with one argument * (the current value). If the selector function produces the same key twice, it * will throw an error. * * Examples: * * ```typescript * ``` */ export declare function mapBy(values: Iterable, selector: Key): Map; export declare function mapBy(values: Iterable, selector: (element: T, index: number) => Key): Map; /** * Splits an iterable into two groups. The first group contains elements * the predicate function returns truthy for, the second group contains elements * the predicate returns falsy for. The predicate is invoked with one argument * (the current value). * * Examples: * * ```typescript * ``` */ export declare function partition(input: Iterable, predicate: (element: T) => boolean): [T[], T[]]; export declare function partition(input: Iterable, predicate: (element: T | U) => element is T): [T[], U[]];