Skip to content

Instantly share code, notes, and snippets.

@readysetmark
Created October 10, 2014 19:05
Show Gist options
  • Save readysetmark/60ad3d2177ad0d74d1c9 to your computer and use it in GitHub Desktop.
Save readysetmark/60ad3d2177ad0d74d1c9 to your computer and use it in GitHub Desktop.
Elixir -> Count # of commas in lines in a file
# 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