what is the offical way to handle multiple list in map() ?

Baz via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Feb 16 01:51:13 PST 2015


while learning the map function, i've landed on this wikipedia 
page(http://en.wikipedia.org/wiki/Map_(higher-order_function)). 
For each language there is a column about handing multiple list, 
i thought it could be a good idea to see how D handle this:

is this the official way ?

---
auto fruits = ["apple", "banana", "orange"][];
auto vegies = ["grass", "salad"][];

// 1 list
auto yougonna = map!(a => "eat " ~ a)(fruits);
// 2 lists
auto youreallygonna = map!( `map!(a => "eat " ~ a)(a)` )([fruits, 
vegies]);

writeln(yougonna.stringof, yougonna);
writeln(youreallygonna.stringof, youreallygonna);
---

which outputs:

---
yougonna["eat apple", "eat banana", "eat orange"]
youreallygonna[["eat apple", "eat banana", "eat orange"], ["eat 
grass", "eat salad"]]
---

The doc doesn't specify anything about multiple lists.




More information about the Digitalmars-d-learn mailing list