Bug 11403 – functions in std.algo can't be used as pred

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-10-31T12:55:00Z
Last change time
2014-01-06T10:30:34Z
Keywords
rejects-valid
Assigned to
nobody
Creator
monarchdodra

Comments

Comment #0 by monarchdodra — 2013-10-31T12:55:31Z
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
Comment #1 by monarchdodra — 2013-10-31T15:33:42Z
Comment #2 by github-bugzilla — 2013-12-19T09:22:36Z
Commit pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/8ce977a8f081fe7832cfb02c235c31de703b29b4 Merge pull request #1676 from monarchdodra/algoPredicable Issue 11403 - functions in std.algo can't be used as pred
Comment #3 by github-bugzilla — 2014-01-06T08:04:00Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/190b8190d4ad43c7f0af5d27a43c644a1559f68a fix Issue 11403 - functions in std.algo can't be used as pred https://github.com/D-Programming-Language/phobos/commit/70bea62290bcb3545ae33b781410f490b8142099 Merge pull request #1819 from monarchdodra/equalEqual fix Issue 11403 - functions in std.algo can't be used as pred
Comment #4 by monarchdodra — 2014-01-06T10:30:34Z
I don't know if we can *really* consider this "resolved", but the most important functions are now pred-compatible. For any other improvements, I think it might be worth looking into a more generic solution, maybe. I'll just close it, and we'll deal with any other issue on a case-by-case basis.