Last active
August 22, 2016 14:21
-
-
Save simonewebdesign/62f31611eaf4d2119c180c743d847360 to your computer and use it in GitHub Desktop.
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
def to_sentence(list) do | |
list |> Enum.reverse |> Enum.reduce(fn(b,c) -> b <> ", " <> c end) | |
end | |
to_sentence ["foo", "bar", "baz"] == "foo, bar, baz" | |
# other cases, using Enum.map_join: | |
Enum.map_join(languages, ", ", fn(_) -> "_" end) | |
Enum.map_join(languages, ", ", fn({_, {lang, _}}) -> "( #{lang}, #{String.downcase lang} )" end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment