How to instantiate a map with multiple functions

Jay Norwood via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Dec 26 20:41:48 PST 2015


On Sunday, 27 December 2015 at 03:22:50 UTC, Jay Norwood wrote:
> I would probably want to associate names with the tuple metric 
> results, and I've seen that somewhere in the docs in parameter 
> tuples.   I suppose I'll try those in place of the current 
> tuple ...
>

This worked to associate names with the tuple values. Just the 
one line modified.
samples.each!((int i, ref 
a)=>tuple!("sample","f1","f2","f3")(i,f1(a),f2(a),f3(a)).writeln());

======= output
Tuple!(int, "sample", ulong, "f1", double, "f2", double, "f3")(0, 
3, 0.7, 0.8)
Tuple!(int, "sample", ulong, "f1", double, "f2", double, "f3")(1, 
6, 0.7, 0.8)
Tuple!(int, "sample", ulong, "f1", double, "f2", double, "f3")(2, 
9, 0.7, 0.8)
Tuple!(int, "sample", ulong, "f1", double, "f2", double, "f3")(3, 
12, 0.7, 0.8)
Tuple!(int, "sample", ulong, "f1", double, "f2", double, "f3")(4, 
15, 0.7, 0.8)
Tuple!(int, "sample", ulong, "f1", double, "f2", double, "f3")(5, 
18, 0.7, 0.8)
Tuple!(int, "sample", ulong, "f1", double, "f2", double, "f3")(6, 
21, 0.7, 0.8)
Tuple!(int, "sample", ulong, "f1", double, "f2", double, "f3")(7, 
24, 0.7, 0.8)
Tuple!(int, "sample", ulong, "f1", double, "f2", double, "f3")(8, 
27, 0.7, 0.8)
Tuple!(int, "sample", ulong, "f1", double, "f2", double, "f3")(9, 
30, 0.7, 0.8)



More information about the Digitalmars-d-learn mailing list