Last active
June 16, 2018 22:49
-
-
Save anthony2025/41aacb77bb49e6640df617814586eb61 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// takes a contract and returns an array of all the persons that passed the filters | |
// add as many filters as you want to the list, e.g.: filterBySalary, etc | |
// sort your filters so the most expensive ones are closer to the end, working with the less data | |
const getFilteredPersons: (Contract, ... => Array<Person>) = _.flow([ | |
_.get('personnel'), | |
filterByPosition(positionFilter), | |
filterByDate(startDate, endDate), | |
filterByStatus(statusFilter, timeRange), | |
_.sortBy(sortKey), | |
R.when( | |
() => sortDirection === 'ascending', // when this predicate is true.. | |
_.reverse, // reverse the persons array, otherwise return array untouched | |
), | |
]); | |
// 'flow' is just a reverse 'compose', _ is lodash, R is ramda | |
// all filterByXXX functions are curried and have a signature of Array<Person> => Array<Person> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment