| 1 | import { ValueIteratee } from '../_internal/ValueIteratee.mjs';
|
|---|
| 2 | import { ValueIteratorTypeGuard } from '../_internal/ValueIteratorTypeGuard.mjs';
|
|---|
| 3 |
|
|---|
| 4 | /**
|
|---|
| 5 | * Creates an array of elements split into two groups, the first of which contains elements
|
|---|
| 6 | * predicate returns truthy for, while the second of which contains elements predicate returns falsey for.
|
|---|
| 7 | * The predicate is invoked with one argument: (value).
|
|---|
| 8 | *
|
|---|
| 9 | * @template T, U
|
|---|
| 10 | * @param {ArrayLike<T> | null | undefined} collection - The collection to iterate over.
|
|---|
| 11 | * @param {(value: T) => value is U} callback - The function invoked per iteration.
|
|---|
| 12 | * @returns {[U[], Array<Exclude<T, U>>]} Returns the array of grouped elements.
|
|---|
| 13 | *
|
|---|
| 14 | * @example
|
|---|
| 15 | * partition([1, 2, 3, 4], n => n % 2 === 0);
|
|---|
| 16 | * // => [[2, 4], [1, 3]]
|
|---|
| 17 | */
|
|---|
| 18 | declare function partition<T, U extends T>(collection: ArrayLike<T> | null | undefined, callback: ValueIteratorTypeGuard<T, U>): [U[], Array<Exclude<T, U>>];
|
|---|
| 19 | /**
|
|---|
| 20 | * Creates an array of elements split into two groups, the first of which contains elements
|
|---|
| 21 | * predicate returns truthy for, while the second of which contains elements predicate returns falsey for.
|
|---|
| 22 | * The predicate is invoked with one argument: (value).
|
|---|
| 23 | *
|
|---|
| 24 | * @template T
|
|---|
| 25 | * @param {ArrayLike<T> | null | undefined} collection - The collection to iterate over.
|
|---|
| 26 | * @param {((value: T) => unknown) | PropertyKey | [PropertyKey, any] | Partial<T>} callback - The function invoked per iteration.
|
|---|
| 27 | * @returns {[T[], T[]]} Returns the array of grouped elements.
|
|---|
| 28 | *
|
|---|
| 29 | * @example
|
|---|
| 30 | * partition([1, 2, 3, 4], n => n % 2 === 0);
|
|---|
| 31 | * // => [[2, 4], [1, 3]]
|
|---|
| 32 | */
|
|---|
| 33 | declare function partition<T>(collection: ArrayLike<T> | null | undefined, callback: ValueIteratee<T>): [T[], T[]];
|
|---|
| 34 | /**
|
|---|
| 35 | * Creates an array of elements split into two groups, the first of which contains elements
|
|---|
| 36 | * predicate returns truthy for, while the second of which contains elements predicate returns falsey for.
|
|---|
| 37 | * The predicate is invoked with one argument: (value).
|
|---|
| 38 | *
|
|---|
| 39 | * @template T
|
|---|
| 40 | * @param {T | null | undefined} collection - The collection to iterate over.
|
|---|
| 41 | * @param {((value: T[keyof T]) => unknown) | PropertyKey | [PropertyKey, any] | Partial<T[keyof T]>} callback - The function invoked per iteration.
|
|---|
| 42 | * @returns {[Array<T[keyof T]>, Array<T[keyof T]>]} Returns the array of grouped elements.
|
|---|
| 43 | *
|
|---|
| 44 | * @example
|
|---|
| 45 | * partition({ a: 1, b: 2, c: 3 }, n => n % 2 === 0);
|
|---|
| 46 | * // => [[2], [1, 3]]
|
|---|
| 47 | */
|
|---|
| 48 | declare function partition<T extends object>(collection: T | null | undefined, callback: ValueIteratee<T[keyof T]>): [Array<T[keyof T]>, Array<T[keyof T]>];
|
|---|
| 49 |
|
|---|
| 50 | export { partition };
|
|---|