You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Suggestion: support multiple filters of the same type #1
In theory I agree that being able to write really short filters and explicitly list each one individually would be nice. I think the user would have to decide what that combination means though. As it stands, simply adding two filters in series is fairly ambiguous. I think I might rewrite your example as
I originally started writing this library with that type of API (as you may recall from my email). But being able to handle both ways of composing multiple filters makes things a bit confusing.
I mostly built this type of composition flexibility in a DB abstraction layer (that I haven't published). It looks something like:
I'm not aware of an API where adding a filter can increase the amount of data returned. && 'feels' common and matches expectations when using collecitions, eg $map->filter($a)->filter($b) == $map->filter($x ==> $a($x) && $b($x))
Except then the only way you could compose the filters with an OR is to explicitly combine them in another function. That feels asymmetric to me.
The use case would be: "I would like classes in namespace A and I would like classes in namespace B and I would not like classes in namespace A\Test". I could see attempting to translate that sentence into a chain of filter calls on the builder very similar, if not identical to, the chain you mention.
I think the word "match" is a little to narrow for generic filters. I also agree with your point about Map::filter being a good example of the usage of the word "filter".
I would be OK having multiple filter calls always remove from the list now that we agree on having multiple include calls always adding to the list. Before, having only a single include and multiple filters, it was difficult to express "I want classes in namespace A and classes in namespace B" by chaining simple filters.
I could also see having methods like includeAllClasses() which would be equivalent to includeClasses($c ==> true). Similarly, have filterAllClasses() equivalent to filterClasses($c ==> false).
Activity
kilahm commentedon Aug 18, 2015
When adding multiple filters, in which way are they combined?
I.e., is
equivalent to
or
In theory I agree that being able to write really short filters and explicitly list each one individually would be nice. I think the user would have to decide what that combination means though. As it stands, simply adding two filters in series is fairly ambiguous. I think I might rewrite your example as
This way the user is forced to think about how the filters are composed into more complex filters.
kilahm commentedon Aug 18, 2015
I originally started writing this library with that type of API (as you may recall from my email). But being able to handle both ways of composing multiple filters makes things a bit confusing.
I mostly built this type of composition flexibility in a DB abstraction layer (that I haven't published). It looks something like:
That would render to and SQL statement something like
Note that this is not allowed
because the grouping is ambiguous.
I really wanted a fluent api to allow arbitrary composition of logical AND and OR statements. It gets pretty hairy, but it can be done.
fredemmott commentedon Aug 18, 2015
I'm not aware of an API where adding a filter can increase the amount of data returned. && 'feels' common and matches expectations when using collecitions, eg $map->filter($a)->filter($b) == $map->filter($x ==> $a($x) && $b($x))
kilahm commentedon Aug 18, 2015
Except then the only way you could compose the filters with an OR is to explicitly combine them in another function. That feels asymmetric to me.
The use case would be: "I would like classes in namespace A and I would like classes in namespace B and I would not like classes in namespace A\Test". I could see attempting to translate that sentence into a chain of
filtercalls on the builder very similar, if not identical to, the chain you mention.fredemmott commentedon Aug 18, 2015
IMO that doesn't match the meaning of the word 'filter'. if there were an 'include()' function I'd expect it to be an OR not an AND
kilahm commentedon Aug 18, 2015
So something like this?
fredemmott commentedon Aug 18, 2015
I'd be fine with that; though here's an alternative this would completely solve the 'filter' naming issue:
As a side note, implementation shortcut: https://github.com/fredemmott/definitions-finder/blob/master/src/FileParser.php#L115-L122
kilahm commentedon Aug 19, 2015
I think the word "match" is a little to narrow for generic filters. I also agree with your point about
Map::filterbeing a good example of the usage of the word "filter".I would be OK having multiple
filtercalls always remove from the list now that we agree on having multipleincludecalls always adding to the list. Before, having only a singleincludeand multiplefilters, it was difficult to express "I want classes in namespace A and classes in namespace B" by chaining simple filters.I could also see having methods like
includeAllClasses()which would be equivalent toincludeClasses($c ==> true). Similarly, havefilterAllClasses()equivalent tofilterClasses($c ==> false).