corvid
corvid

Reputation: 11197

Test against multiple conditions on a filter in ramda

I am currently doing the following:

(projects, query, domain) => compose(
  filter<Project>(propEq('domain', domain)),
  filter<Project>(propSatisfies(test(new RegExp(query)), 'name')),
)(projects)

However, I was wondering if there was a way to avoid the extra iteration by combining the tests. I looked into and and allPass, but neither really meet my parameters. Ideally, I would have something like this:

filter<Project>(
  all([
    propEq('domain', domain),
    propSatisfies(test(new RegExp(query)), 'name'),
  ]),
);

Is this possible in ramda?

Upvotes: 1

Views: 2093

Answers (2)

webNeat
webNeat

Reputation: 2828

I guess this should do what you need

filter<Project>(allPass([
  propEq('domain', domain),
  propSatisfies(test(new RegExp(query)), 'name')
]))

Have you tried that?

Upvotes: 6

9000
9000

Reputation: 40894

You can use and, though it's only for two arguments.

I also wonder what's wrong with joining the predicates with plain &&s, starting from the least probable.

Upvotes: 0

Related Questions