Created
August 4, 2021 15:04
-
-
Save dinocarl/5829fe58818039c30dbd8380ff5d7ef7 to your computer and use it in GitHub Desktop.
Ramda-based every and some Fns that rely on a specific prop
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
const data1 = [ | |
{id: 1, status: true}, | |
{id: 2, status: false}, | |
{id: 3, status: true}, | |
]; | |
const data2 = [ | |
{id: 1, status: true}, | |
{id: 2}, | |
{id: 3, status: true}, | |
]; | |
const andByProp = (propName) => (acc, item) => and( | |
propOr(false, propName, item), acc | |
); | |
const orByProp = (propName) => (acc, item) => or( | |
propOr(true, propName, item), acc | |
); | |
const everyByProp = (propName) => reduce( | |
andByProp(propName), | |
true | |
); | |
const someByProp = (propName) => reduce( | |
orByProp(propName), | |
false | |
); | |
// alternative using any and all | |
const allByProp = (propName) => all( | |
propEq(propName, true), | |
); | |
const anyByProp = (propName) => any( | |
propEq(propName, true), | |
); | |
[ | |
allByProp('status')(data1), | |
allByProp('status')(data2), | |
anyByProp('status')(data1), | |
anyByProp('status')(data2), | |
everyByProp('status')(data1), | |
everyByProp('status')(data2), | |
someByProp('status')(data1), | |
someByProp('status')(data2), | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment