Skip to content

Instantly share code, notes, and snippets.

@evilsoft
Last active April 18, 2020 11:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save evilsoft/914505ae8d65369b494bae625a3b7e51 to your computer and use it in GitHub Desktop.
Save evilsoft/914505ae8d65369b494bae625a3b7e51 to your computer and use it in GitHub Desktop.
import curry from 'crocks/helpers/curry'
import or from 'crocks/logic/or'
import pathSatisfies from 'crocks/predicates/pathSatisfies'
import propSatisfies from 'crocks/predicates/propSatisfies'
const list = [
'nice', 'bad', 'super bad'
]
const data = [
{ fields: { risk: 'good' }, caption: 'bubbles' },
{ fields: { risk: 'good' }, caption: 'nice' },
{ fields: { risk: 'good' }, caption: 'bubbles' },
{ fields: { risk: 'good' }, caption: 'bubbles' },
{ fields: { risk: 'bad' }, caption: 'super bad' },
{ fields: { risk: 'good' }, caption: 'bubbles' },
{ fields: { risk: 'good' }, caption: 'bubbles' },
]
const includes = curry(
(arr, value) => arr.includes(value)
)
const isInList = list => or(
pathSatisfies([ 'fields', 'risk' ], includes(list)),
propSatisfies('caption', includes(list)),
)
data.filter(isInList(list))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment