Enum.map([1,2,3],fn x -> x *2end)Enum.map(%{1=>2,3=>4},fn {k, v} -> k * v end)#[2, 12]Enum.map(%{1=>2,3=>4},fn {k,_} -> k ===3end) #[false, true]%{monday: 28, tuesday: 29, wednesday: 29}|>Enum.map(fn ({d, t}) -> {d, t *1.8+32} end)|>Enum.into(%{})Enum.reduce(1..3,0,fn (new, acc) -> new + acc end)Enum.reduce([%{a: 1}, %{b: 2}], %{}, &Map.merge/2)Enum.filter([1,2,3],fn a -> a in [1,3] end) #[1,3]Enum.filter([1,2,3],fn a -> a notin [1,3] end)Enum.filter(%{a: 1, b: 4},fn {x, y} -> y ===1end)#[a: 1]#returns first val that fn returns truthy val or defaultEnum.find(enum, default,fn)Enum.find([1,2],3,fn x -> x >3end) # 3
Enums are eager so a pipe means an intermediate list is always created
for n <- [1,2,3,4], do: n * nfor n <-1..4, do: n * n # inclusive of both sidesvalues = [good: 1, good: 2, bad: 3, good: 4]for {:good, n} <- values, do: n * n #[1, 4, 16]