mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
feat(collections): improve types of partition
module (#2744)
add type guard overload
This commit is contained in:
parent
7a7385dfe0
commit
7f7583139e
@ -18,12 +18,20 @@
|
||||
* assertEquals(odd, [ 5, 7, 9 ])
|
||||
* ```
|
||||
*/
|
||||
export function partition<T, U extends T>(
|
||||
array: readonly T[],
|
||||
predicate: (el: T) => el is U,
|
||||
): [U[], Exclude<T, U>[]];
|
||||
export function partition<T>(
|
||||
array: readonly T[],
|
||||
predicate: (el: T) => boolean,
|
||||
): [T[], T[]] {
|
||||
const matches: Array<T> = [];
|
||||
const rest: Array<T> = [];
|
||||
): [T[], T[]];
|
||||
export function partition(
|
||||
array: readonly unknown[],
|
||||
predicate: (el: unknown) => boolean,
|
||||
): [unknown[], unknown[]] {
|
||||
const matches: Array<unknown> = [];
|
||||
const rest: Array<unknown> = [];
|
||||
|
||||
for (const element of array) {
|
||||
if (predicate(element)) {
|
||||
|
Loading…
Reference in New Issue
Block a user