A tiny Elixir drop for safely getting values from nested maps.
Switch branches/tags
Nothing to show
Clone or download
Pull request Compare This branch is 8 commits behind mrdougwright:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
config
lib
test
.formatter.exs
.gitignore
README.md
mix.exs
mix.lock

README.md

Unpack

This tiny Elixir drop let's you reach in and unpack any value from a nested map. Returns nil for bad keys, unloaded associations, or empty maps.

Examples

struct = %{player: %{game: %{id: "game-id"}}}
Unpack.get(struct, [:player, :game, :id])
=> "game-id"

struct = %{player: %{}}
Unpack.get(struct, [:player, :game, :id])
=> nil

Docs can be found at https://hexdocs.pm/unpack.

Installation

Availabe as Hex package, the package can be installed by adding unpack to your list of dependencies in mix.exs:

def deps do
  [
    {:unpack, "~> 0.1.2"}
  ]
end

Testing

To test this package, run mix test. To submit a PR, please fork this repo first.