Skip to content

Instantly share code, notes, and snippets.

@joinr
Created January 26, 2015 05:27
Show Gist options
  • Save joinr/de33aeaffbcff043ac32 to your computer and use it in GitHub Desktop.
Save joinr/de33aeaffbcff043ac32 to your computer and use it in GitHub Desktop.
Trying D
//automatically converts lines from char[] to strings, presents
//a range of strings, immutable.
auto stringLines(string filename){
auto f = File(filename);
return f.byLine().map!(a => a.idup);
};
//readSet does a bit much, I'd like to pull out what the foreach is doing,
//obviously a reduction. for now, its string->AssocativeMap String String
auto readSet(string path){
string[string] dict;
foreach(l; stringLines(path)){
dict[l]=l;
}
return dict;
}
//I'd like something along the lines of sum...except
//it's a function::Range T -> AssociativeMap T T, ala the sum
//function I found below
auto sum(T)(T xs){
auto res = reduce!((a,b) => a + b)(0, xs);
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment