Last active
October 22, 2017 17:43
-
-
Save lpil/c782b1ba0f607d4220cea9b048056446 to your computer and use it in GitHub Desktop.
Ways of handling nil
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
id | |
|> get() | |
|> Maybe.and_then(& &1.size) |
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
id | |
|> get() | |
|> case do | |
nil -> | |
nil | |
entity -> | |
entity.size | |
end | |
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
id | |
|> get() | |
|| %{size: default_size} | |
|> (& &1.size).() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment