Created
November 28, 2023 03:27
-
-
Save ThaddeusJiang/21b5f9bf8a047b7cfba20422c1584cc7 to your computer and use it in GitHub Desktop.
Elixir pattern-matching functions
This file contains 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
defmodule DateHelper do | |
def from_date(:undefined) do | |
:undefined | |
end | |
def from_date(:null) do | |
:undefined | |
end | |
def from_date(date) do | |
date.year | |
end | |
end | |
DateHelper.from_date(:undefined) | |
# :undefined | |
DateHelper.from_date(:null) | |
# :undefined | |
DateHelper.from_date(Date.utc_today()) | |
# 2023 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment