Skip to content

Commit

Permalink
Adds array helper
Browse files Browse the repository at this point in the history
  • Loading branch information
eamodio committed Oct 31, 2021
1 parent 4a4dc24 commit 0f27b62
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/system/array.ts
Expand Up @@ -30,6 +30,10 @@ export function countUniques<T>(source: T[], accessor: (item: T) => string): Rec
return uniqueCounts;
}

export function ensure<T>(source: T | T[] | undefined): T[] | undefined {
return source == null ? undefined : Array.isArray(source) ? source : [source];
}

export function filterMap<T, TMapped>(
source: T[],
predicateMapper: (item: T, index: number) => TMapped | null | undefined,
Expand Down

0 comments on commit 0f27b62

Please sign in to comment.