taskPool.reduce vs algorithm.reduce

2018-07-11 Thread Dorian Haglund via Digitalmars-d-learn
Hi. I'm trying to use taskPool.reduce with a delegate, for example: import std.parallelism; int main(string[] args) { int f(int a, int b) { if (args.length > 1) return a+b; else return a-b; } auto res = taskPool.reduce!f([1, 2, 3]); return 0; } But it fails to c

Re: Repeat and chunks

2016-10-25 Thread Dorian Haglund via Digitalmars-d-learn
On Monday, 24 October 2016 at 16:09:44 UTC, ag0aep6g wrote: On 10/24/2016 04:25 PM, Dorian Haglund wrote: The following code crashes with DMD64 D Compiler v2.071.2: import std.algorithm; import std.stdio; import std.range; int main() { repeat(8, 10).chunks(3).writeln(); return 0; } Look

Repeat and chunks

2016-10-24 Thread Dorian Haglund via Digitalmars-d-learn
Hey, The following code crashes with DMD64 D Compiler v2.071.2: import std.algorithm; import std.stdio; import std.range; int main() { repeat(8, 10).chunks(3).writeln(); return 0; } Error message: pure nothrow @nogc @safe std.range.Take!(std.range.Repeat!(int).Repeat).Take std.range.Re

Re: Checking all elements are unique.

2016-08-31 Thread Dorian Haglund via Digitalmars-d-learn
@Edwin: Thank you for the insight about indexed range. @Adrea: Thanks, this looks good. Even if I found it a little obscure at first sight, it's better than my previous solution.

Checking all elements are unique.

2016-08-31 Thread Dorian Haglund via Digitalmars-d-learn
Hello, I have an array of objects of class C which contain a id member. I want to figure out if all the id members are unique using functional primitives. For example, if I have: class C { int id; } and an array of C 'Cs'; My idea was to do: auto ids = Cs.map!(c => c.id); assert(equal(id