digitalmars.D.bugs - [Issue 12272] New: and(), or(), xor() to compose predicates
- d-bugmail puremagic.com (25/25) Feb 27 2014 https://d.puremagic.com/issues/show_bug.cgi?id=12272
- d-bugmail puremagic.com (10/10) Feb 27 2014 https://d.puremagic.com/issues/show_bug.cgi?id=12272
- d-bugmail puremagic.com (13/25) Feb 28 2014 https://d.puremagic.com/issues/show_bug.cgi?id=12272
- d-bugmail puremagic.com (12/17) Feb 28 2014 https://d.puremagic.com/issues/show_bug.cgi?id=12272
- d-bugmail puremagic.com (11/21) Feb 28 2014 https://d.puremagic.com/issues/show_bug.cgi?id=12272
- d-bugmail puremagic.com (14/19) Feb 28 2014 https://d.puremagic.com/issues/show_bug.cgi?id=12272
- d-bugmail puremagic.com (10/18) Feb 28 2014 https://d.puremagic.com/issues/show_bug.cgi?id=12272
https://d.puremagic.com/issues/show_bug.cgi?id=12272 Summary: and(), or(), xor() to compose predicates Product: D Version: D2 Platform: All OS/Version: All Status: NEW Severity: enhancement Priority: P2 Component: Phobos AssignedTo: nobody puremagic.com ReportedBy: bearophile_hugs eml.cc In Java8 there are functions like and() or() xor() that are handy to compose predicates: Predicate<String> startsWithJ = (n) -> n.startsWith("J"); Predicate<String> fourLetterLong = (n) -> n.length() == 4; names.stream().filter(startsWithJ.and(fourLetterLong)) In D: auto startsWithJ = (string n) => n.startsWith("J"); auto fourLetterLong = (string n) => n.length == 4; names.filter!(and!(startsWithJ, fourLetterLong)) -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 27 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12272 w0rp <devw0rp gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |devw0rp gmail.com I like it. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 27 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12272 yebblies <yebblies gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |yebblies gmail.comIn Java8 there are functions like and() or() xor() that are handy to compose predicates: Predicate<String> startsWithJ = (n) -> n.startsWith("J"); Predicate<String> fourLetterLong = (n) -> n.length() == 4; names.stream().filter(startsWithJ.and(fourLetterLong)) In D: auto startsWithJ = (string n) => n.startsWith("J"); auto fourLetterLong = (string n) => n.length == 4; names.filter!(and!(startsWithJ, fourLetterLong))Lambdas make this pretty easy... names.filter!(s => s.startsWithJ && s.fourLetterLong) Slightly longer, but _much_ more flexible. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 28 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12272Lambdas make this pretty easy... names.filter!(s => s.startsWithJ && s.fourLetterLong) Slightly longer, but _much_ more flexible.With those templates you can define a new predicate in point-free style (std.functional.compose!() does something similar for arbitrary functions): alias two = and!(startsWithJ, fourLetterLong); With lambdas it becomes similar to: enum two = (in string s) => s.startsWithJ && s.fourLetterLong; So are you suggesting to close down this ER because it's not useful enough? -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 28 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12272With those templates you can define a new predicate in point-free style (std.functional.compose!() does something similar for arbitrary functions):IIRC std.functional.compose predates lambdasalias two = and!(startsWithJ, fourLetterLong); With lambdas it becomes similar to: enum two = (in string s) => s.startsWithJ && s.fourLetterLong;I expect we will soon be able to do this: alias two = s => s.startsWithJ && s.fourLetterLong;So are you suggesting to close down this ER because it's not useful enough?I don't think this is worth adding to phobos. Of course what you do with this ER is up to you. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 28 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12272 bearophile_hugs eml.cc changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |INVALIDI expect we will soon be able to do this: alias two = s => s.startsWithJ && s.fourLetterLong;I see no plans for this yet.Of course what you do with this ER is up to you.Your opinion is always welcome.I don't think this is worth adding to phobos.OK, closed. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 28 2014
https://d.puremagic.com/issues/show_bug.cgi?id=12272The plans are in my head. You can currently do this: alias Alias(alias a) = a; alias two = Alias!(s => s.startsWithJ && s.fourLetterLong); So the limitation appears to just be syntactical. -- Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------I expect we will soon be able to do this: alias two = s => s.startsWithJ && s.fourLetterLong;I see no plans for this yet.
Feb 28 2014