Closed mirfilip closed 7 years ago
If I understand correctly, you can achieve this by just filtering and specifying the condition A OR (B AND C)
in the filter function. If this is not the case, can you elaborate please?
@DusanKasan Yes, you can do that. I'd rather create these filters as a separate classes / callables. Yes, I can do this and then "glue" it all with my own "master filter" that performs the logical condition. Then, I have one master filter to pass to filter function.
I just wondered whether this lib can do different logical conditions than standard filter
calls chained (resulting in AND between them):
Collection::from([1, 3, 3, 2])
->filter(function ($value) {
return $value > 2;
})
->filter(function ($value) {
return $value < 4;
})
etc.
Other similar libraries sometimes have methods like or()
, and()
etc. to build such composite criteria.
What you are describing sounds pretty much like a query builder and is out of scope for this library. If you would use a query builder to create a query for your data you can apply it in the filter method. But as I said the library doesn't support this.
Right, fair enough! Thank you.
Hi @mirfilip
the issue is closed already, but maybe you could find interesting this lib. You could be the one providing "the Knapsack datasource" :). Maybe it is not even needed a new datasource.
Hope it helps.
@davidmpaz I've already seen that lib, looks promising. I won't guarantee, but if I find time, I could tackle that. Thx again.
Hi, first of all - what a library! I tip my hat.
I'm looking for a lib where I could filter a collection (or create a "collection pipeline") based on a boolean expressions that are not only AND-ed.
Example: I have a collection:
and would like to apply a logical filter that looks like
A OR (B AND C)
where: A -testField
contains a lettero
B -otherValue
is even C -testField
consists of 3 letters andotherValue
is lower than 10The boolean statement and A, B, C are just random examples.
I know it can be done by creating two collections: one for
A
, one forB AND C
and then concatenating them. I'm looking for a more streamlined way though as the way to do it would differ with a way the statement look and would not scale well.Any ideas?