Skip to content

Access Elixir maps and structs, protected from `nil`

License

Notifications You must be signed in to change notification settings

infinitered/maybe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Maybe

Hex.pm Build Status

Access nested Elixir maps and structs, protected from nil. Somewhat similar to "Optionals" in Apple Swift.

import Maybe

info = %{city: %{name: "Portland"}}
maybe(info.city.name)
# => "Portland"

map = %{}
maybe(map.city.name)
# => nil

See the original forum post for more an explanation of the problem this package solves.

Installation

Add maybe to your list of dependencies in mix.exs:

def deps do
  [
    {:maybe, "~> 1.0.0"}
  ]
end

See the documentation for more details.