Add match predicate?
chocolateboy opened this issue · 8 comments
Or predicate.matches
or predicate.like
. Takes a regex and returns true if the supplied value matches.
See here for an example.
Are you saying that predicate.matches(/foo/, 'foo') === /foo/.test('foo');
? I can see from your example that you'd like the power of currying.
This does seem like a nice function to add. I'll do it.
Did you see jdalton's response about bind
?
_.parition(process.argv.slice(2), RegExp.prototype.test, /^-/);
is certainly a nice solution. I sometimes do this same thing with filter/every/some
. [1,2,'a'].filter(RegExp.prototype.test, /\d/); // [1,2]
, or use bind.
var matches = RegExp.prototype.test.bind(/foo/);
matches('foo'); // true
@chocolateboy Thoughts?
Are you saying that predicate.matches(/foo/, 'foo') === /foo/.test('foo');?
Yes.
Did you see jdalton's response about bind?
Yes. I found it unsatisfying. As mentioned, regexps are currently useless as predicates and making them useful has been requested before and will probably be requested again.
lol okay. I also like the idea. I can probably get this in today.
Sorry this took so long. I got very busy at work and lazy at home! lol