Skip to content

Instantly share code, notes, and snippets.

@simonewebdesign
Last active August 22, 2016 14:21
Show Gist options
  • Save simonewebdesign/62f31611eaf4d2119c180c743d847360 to your computer and use it in GitHub Desktop.
Save simonewebdesign/62f31611eaf4d2119c180c743d847360 to your computer and use it in GitHub Desktop.
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