October 31, 2013 [Issue 11403] New: functions in std.algo can't be used as pred | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=11403 Summary: functions in std.algo can't be used as pred Product: D Version: D2 Platform: All OS/Version: All Status: NEW Keywords: rejects-valid Severity: normal Priority: P2 Component: Phobos AssignedTo: nobody@puremagic.com ReportedBy: monarchdodra@gmail.com --- Comment #0 from monarchdodra@gmail.com 2013-10-31 12:55:31 PDT --- There are a ton of functions in std.algorithm that can be customized with a predicate. At ton of them can also be used as predicates themselves. Here is a cool example: assert(equal!equal([[1, 2], [3, 4]], iota(1, 5).chunks(2))); The problem with this piece of code is that: The inner "equal" only works because it itself doesn't have a predicate. The outer "equal" works because it takes arguments. However, neither of this works: alias fun = equal!equal; //Nope equal!(equal!equal))(3Dmatrix1, 3Dmatrix2); //Nope It is *not* possible to declare an algorithm function with a predicate, unless you also specify the argument types. Long story short, they are not eagerly specialize-able. "equal" (I think) is the most obvious offender, but so are any/all: import std.ascii : isWhite; assert( all!(any!isWhite)(["a a", "b b"])); //Nope assert(!any!(all!isWhite)(["a a", "b b"])); //Nope Any function that takes a pred (+an argument) and returns a bool is faulty. Here is a (probably incomplete) list: -equal -canFind -any -all -cmp -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
October 31, 2013 [Issue 11403] functions in std.algo can't be used as pred | ||||
---|---|---|---|---|
| ||||
Posted in reply to monarchdodra@gmail.com | http://d.puremagic.com/issues/show_bug.cgi?id=11403 --- Comment #1 from monarchdodra@gmail.com 2013-10-31 15:33:42 PDT --- https://github.com/D-Programming-Language/phobos/pull/1676 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation