Skip to content

Commit

Permalink
refactor(utils): moves times; isPromise
Browse files Browse the repository at this point in the history
  • Loading branch information
dzucconi committed Aug 29, 2019
1 parent e1d7c8e commit 1f80e9e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/lib/times.ts

This file was deleted.

8 changes: 8 additions & 0 deletions src/lib/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
export function isDefined<T>(value: T | undefined | null): value is T {
return <T>value !== undefined && <T>value !== null;
}

export const isPromise = (val: void | Promise<any>): val is Promise<any> =>
val && (<Promise<any>>val).then !== undefined;

export const times = <T>(n: number, fn: (num: number) => T): T[] =>
Array(n)
.fill(undefined)
.map((_, i) => fn(i));

0 comments on commit 1f80e9e

Please sign in to comment.