Last active
October 3, 2019 06:45
-
-
Save ishikawa/a5e72c2d85a8b32c73b24eae0190ff6f to your computer and use it in GitHub Desktop.
Passing in options: Maps vs. Keyword lists
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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