How to convert Map to array?

Daniel Murphy yebblies at
Mon Jan 10 15:13:50 PST 2011

"Sean Eskapp" <eatingstaples at> wrote in message 
news:igdu78$18kt$1 at
> I'm trying to use the array() function in std.array to convert a 
> transformed
> array using map (std.algorithm) back to a dynamic array, from a Map. I 
> keep
> getting a cryptic error "object.Exception at C:\Program Files
> (x86)\D\dmd2\windows\bin\..\..\src\phobos\std\
> algorithm.d(426): Cannot reduce an empty range w/o an explicit seed 
> value.".
> Am I misunderstanding how this is supposed to work?

You're calling reduce on an empty range.

reduce!"a*b"([1, 2, 3]); // fine, translates to 1 * 2 * 3
reduce!"a*b"([7]); // also fine, translates to 7
reduce!"a*b"([]); // what should this be?

Luckily you can call reduce with an extra argument giving the seed value:

reduce!"a*b"(1, []); // Calculates product for both empty and non-empty 

More information about the Digitalmars-d mailing list