Skip to content

Instantly share code, notes, and snippets.

@anthony2025
Last active June 16, 2018 22:49
Show Gist options
  • Save anthony2025/41aacb77bb49e6640df617814586eb61 to your computer and use it in GitHub Desktop.
Save anthony2025/41aacb77bb49e6640df617814586eb61 to your computer and use it in GitHub Desktop.
// 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