Created
January 26, 2015 05:27
-
-
Save joinr/de33aeaffbcff043ac32 to your computer and use it in GitHub Desktop.
Trying D
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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