Last active
February 26, 2020 13:09
-
-
Save reidev275/1337d1d9cdb07c410daec53f59d2373a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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