import { ArrayIterator, MapIterator, ObjectIterator, SetIterator, StringIterator, Tuple } from './types' /** * @description * Iterate over `collection` and apply `fn` to each item, * returning an array where the first element contains all items * for which `fn` returned a truthy value, and the second element * contains all items for which it returned a falsy value. * * @parameters * | name | type | description | * | :--: | :--: | ----------- | * | collection | `object` | Object-like value to split | * | fn | `Function` | Predicate with which to split items | * * @returns `[truthy, falsy]` * * @example * partition([true, false, true, false], v => v === true) * // -> [[true, true], [false, false]] * * partition({ keyOne: true, keyTwo: false }, v => v === true) * // -> [{ keyOne: true }, { keyTwo: false }] * * partition('some arbitrary string', v => v === ' ') * // -> [' ', 'somearbitrarystring'] * * partition(new Map([['keyOne', true], ['keyTwo', false]]), v => v === true) * // -> [ Map {'keyOne' => true}, Map {'keyTwo' => false} ] * * partition(new Set(['Joe', 'Jerry', 'Rick', 'Bob']), v => v.startsWith('J')) * // -> [ Set {'Joe', 'Jerry'}, Set {'Rick', 'Bob'} ] * * @since v1.0.0 * @tag collections */ interface Partition { (collection: T, fn: StringIterator): Tuple (collection: T[], fn: ArrayIterator): Tuple (collection: Map, fn: MapIterator): Tuple> (collection: Set, fn: SetIterator): Tuple> (collection: T, fn: ObjectIterator): Tuple> } declare const partition: Partition export default partition