Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ad-hoc filtering of directives #258

Merged
merged 3 commits into from Sep 9, 2014
Merged

Support ad-hoc filtering of directives #258

merged 3 commits into from Sep 9, 2014

Conversation

n8han
Copy link
Member

@n8han n8han commented Sep 8, 2014

Directives currently have no-op filter method that was added to support extraction of parameter directive tuples. This pull request moves filter functionality to a FilterDirective subtype so that the potentially surprising behavior of a no-op filter is now limited to and-ed parameter directives.

Further, these changes allow us to support proper filtering in cases where orElse is used. We can now construct a directive that knows how to fail for some conditions, and add more failure conditions via the if clause of a for expression. This behavior is demonstrated in an example added to DirectiveSpec.

Nathan Hamblen added 3 commits September 7, 2014 22:10
isolates other directives from the no-op filter strangeness, and opens
up some possibilities of useful filtering.
When a directive is constructed via `when ... orElse` or
`Directive#orElse`, we can filter a successful result and fall back to
the orElse directive. This allows for ad-hoc extention of directive
requirements in the `if` clause of a for expression.

Added a demonstration to DirectiveSpec.
@softprops
Copy link
Member

Seems to fit the typical 'withfilter' bill. Most impls of this pattern define and inner class of the type being filtered called 'WhithFilter'. Any thoughts on making 'FilterDirective' and inner class of 'Directive' named 'Filtered' or something?

@n8han
Copy link
Member Author

n8han commented Sep 8, 2014

If you link to an example we can confirm, but I think the difference is that this FilterDirective class provides a withFilter method, while WithFilter are typically classes of objects returned by such a method.

@softprops
Copy link
Member

Ah, I think I missed that. Here's an example in travsersablelike https://github.com/scala/scala/blob/2.11.x/src/library/scala/collection/TraversableLike.scala. What I like about inner classes is that it reduces the number of names brought into scope at the package level which is good if they aren't intended to be directly instantiated in user code. Do you think users will ever be instantiating instances of FilterDirectives outside the context of an instance of a Directive?

@n8han
Copy link
Member Author

n8han commented Sep 9, 2014

Yes, I've done that in this pull request.

softprops added a commit that referenced this pull request Sep 9, 2014
Support ad-hoc filtering of directives
@softprops softprops merged commit c82d508 into 0.8.2 Sep 9, 2014
@n8han n8han added this to the 0.8.2 milestone Sep 10, 2014
@xuwei-k xuwei-k deleted the directive_filter branch November 29, 2016 04:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants