predicates-rs icon indicating copy to clipboard operation
predicates-rs copied to clipboard

feat: Add str::contains_all function

Open Techassi opened this issue 1 year ago • 8 comments

This PR adds the str::contains_all predicate function. It allows one to check if the input contains all provided needles.

use predicates::prelude::*;

let predicate_fn = predicate::str::contains_all(vec!["One", "Two", "Three"]);

assert_eq!(true, predicate_fn.eval("One Two Three"));
assert_eq!(false, predicate_fn.eval("One Two Four"));
assert_eq!(false, predicate_fn.eval("Four Five Six"));

Techassi avatar Jul 16 '23 16:07 Techassi

In your example, shouldn't it be a vec with multiple strings as predicates, or am I misunderstanding something?

let predicate_fn = predicate::str::contains_all(vec!["One", "Two", "Three"]);

mre avatar Jul 17 '23 08:07 mre

You are absolutely correct. I somehow forgot to add the commas.

EDIT: I added the commas in my comment above and in the doc test in 45d4a17.

Techassi avatar Jul 17 '23 08:07 Techassi

If we move forward with this, can you squash your commits?

epage avatar Jul 17 '23 13:07 epage

Yes, I can do that once we are ready with this PR.

Techassi avatar Jul 17 '23 17:07 Techassi

Yes, I can do that once we are ready with this PR.

The downside to that is it requires an extra ping-pong between us to get this in, causing more context switches, and being fairly easy to fall through the cracks

epage avatar Jul 17 '23 17:07 epage

The downside to that is it requires an extra ping-pong between us to get this in, causing more context switches, and being fairly easy to fall through the cracks

Can't we just use squash-merge? Then GitHub would do the heavy lifting for us :)

Techassi avatar Jul 17 '23 18:07 Techassi

Can't we just use squash-merge? Then GitHub would do the heavy lifting for us :)

Not the most ideal experience and I don't like blindly squashing PRs but only doing it as a last resort because we should preserve multiple commits when they are relevant.

epage avatar Jul 18 '23 01:07 epage

I now squashed all previous commits (Adding the function, updating the docs, and merging changes from main).

I will now continue to work on the unresolved conversations above.

Techassi avatar Sep 09 '23 12:09 Techassi