Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- defmodule InlineLookup do
- # Examples how to handle a static lookup table in Elixir.
- def example1(x) do
- %{1 => "a", 2 => "b", 3 => "c"}[x]
- # Could also be a attribute
- # Should be the same as:
- Map.get(%{1 => "a", 2 => "b", 3 => "c"}, x, nil)
- end
- def example2(1), do: "a"
- def example2(2), do: "b"
- def example2(3), do: "c"
- def example2(_), do: nil
- # Functions calls, could be generated at compile time from attribute
- # Not using a map here, so could be optimied by compiler maybe.
- end
Add Comment
Please, Sign In to add comment