+
+ def zero?(0), do: true
+ def zero?(x) when is_integer(x), do: false
+end
+
+IO.inspect Math.sum(1, 2)
+IO.inspect Math.zero?(1)
+
+fun = &Math.zero?/1 # '&' to capture a function as a lambda (and use with high level functions).
+IO.inspect fun.(0) # Calling it with same syntaxe as lambdas.
+
+fun2 = &(&1 + 1) # Shortcut syntax: '&1' is the first parameter.
+fun3 = &"Good #{&1}"
+IO.inspect fun2.(3) # Print 4.
+
+# Enum.
+IO.puts "=== Enum ==="
+IO.inspect Enum.map([1, 2, 3], &(2 * &1))
+IO.inspect Enum.map(%{1 => 2, 3 => 4}, fn {k, v} -> k * v end)
+IO.inspect Enum.map(1..10, &(3 * &1))
+IO.inspect Enum.reduce(1..3, 0, &+/2) # 1 + 2 + 3.
+
+odd? = &(rem(&1, 2) != 0)
+IO.inspect 1..100_000 |> Enum.map(&(3 * &1)) |> Enum.filter(odd?) |> Enum.sum
+
+# Process.
+IO.puts "=== Process ==="
+pid =
+ spawn fn ->
+ receive do
+ {:hello, sender, msg} ->
+ IO.puts "Message received: '#{msg}'"
+ send sender, :ok
+ end
+ end
+
+
+send pid, {:hello, self(), "Salut"}
+receive do
+ :ok -> IO.puts "Message delivered!"
+after
+ 1_000 -> IO.puts "Message not delivered :("
+end
+
+IO.puts "=== State ==="
+defmodule KV do # Key-Value.
+ def stark_link do
+ Task.start_link(fn -> loop %{} end)
+ end
+
+ defp loop(map) do
+ receive do
+ {:get, key, caller} ->
+ send caller, Map.get(map, key)
+ loop map
+ {:put, key, value} ->
+ loop Map.put(map, key, value)
+ end
+ end
+end
+
+{:ok, kv} = KV.stark_link
+send kv, {:put, :a, 42}
+send kv, {:put, :b, 420}
+send kv, {:get, :b, self()}
+receive do
+ value -> IO.puts "Value received: #{value}"