debug scope(failure) writefln("Unittest Failure :%s(%s) ", __FILE__, __LINE__); debug scope(success) {writefln("Unittest Success :%s(%s)", __FILE__, __LINE__); stdout.flush();} // test cases : http://zvon.org/other/haskell/Outputprelude/scanl_f.html assert(equal(scan!"a / b"(64, [4, 2, 4]), [64, 16, 8, 2])); int[] none; assert(equal(scan!"a / b"(3, none), [3])); import std.algorithm : max; assert(equal(scan!max(5, [1, 2, 3, 4]), [5, 5, 5, 5, 5])); assert(equal(scan!max(5, [1, 2, 3, 4, 5, 6, 7]), [5, 5, 5, 5, 5, 5, 6, 7])); assert(equal(scan!"2*a + b"(4, [1, 2, 3]), [4, 9, 20, 43]));
reduceは、レンジのすべての要素をたどりますが、scanはその途中結果を要素としてもつレンジです。