https://github.com/infinitered/maybe
Access Elixir maps and structs, protected from `nil`
https://github.com/infinitered/maybe
elixir optionals
Last synced: 9 months ago
JSON representation
Access Elixir maps and structs, protected from `nil`
- Host: GitHub
- URL: https://github.com/infinitered/maybe
- Owner: infinitered
- License: mit
- Created: 2018-02-05T16:50:53.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-05T17:37:37.000Z (almost 8 years ago)
- Last Synced: 2025-04-21T13:53:13.589Z (9 months ago)
- Topics: elixir, optionals
- Language: Elixir
- Size: 10.7 KB
- Stars: 25
- Watchers: 11
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Maybe
[](https://hex.pm/packages/maybe)
[](https://travis-ci.org/infinitered/maybe)
Access nested Elixir maps and structs, protected from `nil`. Somewhat similar to "Optionals" in Apple Swift.
```elixir
import Maybe
info = %{city: %{name: "Portland"}}
maybe(info.city.name)
# => "Portland"
map = %{}
maybe(map.city.name)
# => nil
```
See the original [forum post](https://elixirforum.com/t/maybe-nil-protection-for-nested-structs/468) for
more an explanation of the problem this package solves.
## Installation
Add `maybe` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:maybe, "~> 1.0.0"}
]
end
```
See [the documentation](https://hexdocs.pm/maybe) for more details.