Reputation: 1420
I heve a static collection. And I want to check for any match by value each time, the value is changed.
Now I have:
var isOk = R.any(item => item.test(value), items);
What I want:
To store a function in other place and to call it like:
var isOk = checkMatch(value);
Any ideas? Thx.
UPDATE I'm looking for solution in Ramda way. Something with changind call order of R.__
Upvotes: 0
Views: 51
Reputation: 50807
I don't know for sure that your test items are regular expressions to use on Strings, but if they are, you might try something like this:
const anyMatch = curry((regexes, val) => any(regex => test(regex, val), regexes))
const testFiles = anyMatch([/test\/(.)+\.js/i, /\.spec\.js/i])
testFiles('foo.js') //=> false
testFiles('test/foo.js') //=> true
testFiles('foo.spec.js') //=> true
And this looks clean to me, and very much in the spirit of Ramda. If you wanted to make it point-free, you could do this:
const anyMatch = useWith(flip(any), [identity, flip(test)])
But I find that much less readable. To me, point-free is a tool worth using when it improves readability, and to avoid when it doesn't.
You can see this in action on the Ramda REPL.
Upvotes: 1
Reputation: 169308
Wrap it in a closure that takes value
.
var isOk = (value) => R.any(item => item.test(value), items);
var isOk_foobar = isOk('foobar');
Upvotes: 2