Created
October 10, 2014 19:05
-
-
Save readysetmark/60ad3d2177ad0d74d1c9 to your computer and use it in GitHub Desktop.
Elixir -> Count # of commas in lines in a file
This file contains hidden or 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
# NOT idiomatic code.. just threw this together | |
# the need to unfold the stream for codepoints feels icky | |
# Plus not mapping counts across all lines, doing Enum.at! YUCK! | |
temp = File.stream!("path/to/file") | |
tempx = Enum.map(temp, fn line -> Stream.unfold(line, &String.next_codepoint/1) end) | |
tempy = Enum.map(tempx, fn line -> Enum.filter(line, fn x -> x == "," end) end) | |
Enum.count(Enum.at(tempy, 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment