Skip to content

Instantly share code, notes, and snippets.

@ishikawa
Last active October 3, 2019 06:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ishikawa/a5e72c2d85a8b32c73b24eae0190ff6f to your computer and use it in GitHub Desktop.
Save ishikawa/a5e72c2d85a8b32c73b24eae0190ff6f to your computer and use it in GitHub Desktop.
Passing in options: Maps vs. Keyword lists
# https://elixirforum.com/t/passing-in-options-maps-vs-keyword-lists/1963
@doc """
do foo operation
## Options
- `:option1` - option 1
- `:option2` - option 2
"""
@spec foo_operation(Foo.t(), [option]) :: {:ok, Foo.t()} | :error
when option: {:option1, atom} | {:option2, integer}
def foo_operation(foo, opts \\ []) do
opts = Enum.into(opts, %{option1: :default, option2: 15})
do_foo_operation(foo, opts)
end
@spec do_foo_operation(Foo.t(), map) :: {:ok, Foo.t()} | :error
defp do_foo_operation(foo, %{option1: option1, option2: option2}) do
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment