Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. # Simplified representation of source data
  2. data = ["A", "B", "B", "A", "C", "A", "D"]
  3. Stream.transform(data, "", fn(line, acc) ->
  4. if line == "A" do
  5. if acc == "", do: {[], line}, else: {[acc], line}
  6. else
  7. {[], acc <> line}
  8. end
  9. end) |> Enum.to_list
  10. # Desired: ["ABB", "AC", "AD"]
  11. # Result: ["ABB", "AC"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement