Skip to content

Commit

Permalink
feat: arrayOf
Browse files Browse the repository at this point in the history
  • Loading branch information
LuciNyan committed Feb 28, 2023
1 parent 9c5ef4d commit 9c95c26
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/operator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,15 @@ export function intersection<T extends any[]>(
}
}

export function arrayOf<T extends unknown[]>(...guards: { [K in keyof T]: Guard<T[K]> }): Guard<T> {
return function (x: unknown): x is T {
if (!Array.isArray(x)) {
return false
}

return x.every((item) => guards.some(guard => guard(item)))
}
}

export const or = union
export const and = intersection

0 comments on commit 9c95c26

Please sign in to comment.