Sowewanttoallowcomplex-dynamicqueriesinrell.Let's say that there is an entity like such:entity character { name; color; age: integer; height: integer; weight: integer;}We want user to be able to filter by none / some / all those parameters both with inclusive and / or exclusive clauses.E.g* I want to get the characters whose color is not black* I want to get the characters whose color is not black and age is higher than 18One exclusive clause can always be converted into an inclusive clause.i.e.* I dont'wantitblack=Iwantitorange,red,green(allthecolorsbutblack)ExamplequeryqueryfilterCharacter(name,colors:set<color>,ageIntervals:list<(integer,integer)>,heightIntervals:list<(integer,integer)>,weightIntervals:list<(integer,integer)){returncharacter@*{name,color:any(colors),age:notall(ageIntervals)height:height}}exact|heightoneamongthe|set<height>|@heightsall|set<height>|@*heightsnone|set<height>|not@heightsenumcolor{black,white}valmaxHeight=200;//||valmaxHeight=Integer.MAX_VALUE;valallowedAges=set<integer>(18,21,65);aliasint_interval{minVal:integer,maxVal:integer}functionfilterCharacterByAllProperties(height:set<int_interval>,color=color.*){characters@*{height<=maxHeight,height>=minHeight,//onlyallow18,21,65age=@allowedAges,//notallow18,21,65age=not@allowedAgesheight=]18,65[, height = [18, 65[, ]73,94],color=(color.*||color.white||color.black),}}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.