How to apply a function to a container/array ?
    Domingo via Digitalmars-d-learn 
    digitalmars-d-learn at puremagic.com
       
    Wed Oct 15 16:26:44 PDT 2014
    
    
  
Ideally I want to use something like this:
---------
import std.stdio;
import std.string;
import std.algorithm;
import std.conv;
void main()
{
	string[] ar = [" dad ", " blue "];
	writeln(typeid(ar));
	
	//ar.each(writeln);
	//ar.map!writeln;
	//ar.apply!writeln;
	
	//string[] ar_striped = ar.map!strip;
	//string[] ar_striped = ar.apply!strip;
	//string[] ar_striped = ar.each!strip;
	
	//ar_striped.each!writeln;
	//ar_striped.apply!writeln;
	//ar_striped.map!writeln;
	
	
	alias stringize = map!(to!string);
	auto sz = stringize([ 1, 2, 3, 4 ]);
	writeln(typeid(sz));
	assert(equal(sz, [ "1", "2", "3", "4" ]));
}
---------
But none of then work, any idea of how to that in D ?
Cheers !
    
    
More information about the Digitalmars-d-learn
mailing list