今天的文章稍微整理一些實作上一定會用到的模組函式,當然實際上會有更多更多,但這篇文章所舉出的,會是幾乎一定會去使用的function。
iex> Enum.map([1, 6, 3], fn x -> x + 1 end)
[2, 7, 4]
iex> Enum.map([1, 6, 3], fn x -> x < 4 end)
[1, 3]
iex> Enum.join([1, 2, 5, 4])
"1254"
iex> Enum.join([1, 2, 5, 4], ",")
"1,2,5,4"
iex> Enum.with_index([1, 2, 5, 4])
[{1, 0}, {2, 1}, {5, 2}, {4, 3}]
iex> Enum.with_index([1, 2, 5, 4])
|> Enum.map(&("Key of #{elem(&1, 0)} is #{elem(&1, 1)}"))
["Key of 1 is 0", "Key of 2 is 1", "Key of 5 is 2", "Key of 4 is 3"]