Skip to content

Instantly share code, notes, and snippets.

@reidev275
Last active February 26, 2020 13:09
Show Gist options
  • Save reidev275/1337d1d9cdb07c410daec53f59d2373a to your computer and use it in GitHub Desktop.
Save reidev275/1337d1d9cdb07c410daec53f59d2373a to your computer and use it in GitHub Desktop.
//greater than or equal
export const gte = <A, K extends keyof A>(field: K, val: A[K]): Filter<A> =>
or(greater(field, val), equals(field, val));
//less than or equal
export const lte = <A, K extends keyof A>(field: K, val: A[K]): Filter<A> =>
or(less(field, val), equals(field, val));
//combine 1 to many filters returning true if all are true (and)
export const all = <A>(...dsl: Filter<A>[]): Filter<A> =>
dsl.reduce((p, c) => and(p, c));
//combine 1 to many filters returning true if any are true (or)
export const any = <A>(...dsl: Filter<A>[]): Filter<A> =>
dsl.reduce((p, c) => or(p, c));
//essentially sql's in operator. Given a field and a collection of values
//this returns true if any are true.
export const oneOf = <A, K extends keyof A>(field: keyof A, ...vals: A[K][]): Filter<A> =>
any(...vals.map(x => equals(field, x)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment