www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13595] New: A possible problem with std.algorithm.groupBy

https://issues.dlang.org/show_bug.cgi?id=13595

          Issue ID: 13595
           Summary: A possible problem with std.algorithm.groupBy
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: bearophile_hugs eml.cc

Perhaps I have not fully understood the usage of std.algorithm.groupBy. This is
Haskell:

Prelude> import Data.List
Prelude Data.List> groupBy (\x y -> (mod (x*y) 3) == 0) [1,2,3,4,5,6,7,8,9]
[[1],[2,3],[4],[5,6],[7],[8,9]]



D code:

void main() {
    import std.stdio, std.algorithm, std.array, std.range;
    [1,2,3,4,5,6,7,8,9]
    .groupBy!((x, y) => ((x * y) % 3) == 0)
    .take(20)
    .writeln;
}

Output of the D code:

[[], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [], [],
[]]

Please close down this issue if this behavour is expected and correct.

--
Oct 10 2014