Last active
August 29, 2015 14:25
-
-
Save parsonsmatt/52589ba1d4d555ee1e45 to your computer and use it in GitHub Desktop.
muh filters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
WhichBar = | |
Filter::Lift | |
| Filter::Singular.new( | |
attribute: :open, | |
value: true | |
) | |
| Filter::Collection.new( | |
attribute: :people, | |
aggregator: { | |
klass: :compare, | |
options: { | |
attribute: :age, | |
value: 21, | |
comparator: :>=, | |
reductor: :all? | |
} | |
} | |
) | |
Person = Struct.new(:age) | |
nope = (18..22).map(&Person.method(:new)) | |
bad_news = (19..24).map(&Person.method(:new)) | |
okay = (25..35).map(&Person.method(:new)) | |
fine = (30..45).map(&Person.method(:new)) | |
Bar = Struct.new(:people, :open) | |
trappeze = Bar.new(okay, true) | |
nineties = Bar.new(nope, true) | |
eighties = Bar.new(nope, false) | |
some_pig = Bar.new(fine, false) | |
bars = [trappeze, nineties, eighties, some_pig] | |
WhichBar.new(bars).records.first | |
=> trappeze |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment