landau / predicate

Adding clarity and conciseness to your JS through predicates

Home Page:http://landau.github.io/predicate

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add match predicate?

chocolateboy opened this issue · comments

Or predicate.matches or predicate.like. Takes a regex and returns true if the supplied value matches.

See here for an example.

commented

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
commented

@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.

commented

lol okay. I also like the idea. I can probably get this in today.

commented

Sorry this took so long. I got very busy at work and lazy at home! lol

commented

Feel free to fix #4 :)