Created
September 4, 2022 22:28
-
-
Save rugyoga/0d3ec79b970b412b2dc618160d974faf to your computer and use it in GitHub Desktop.
Is this value empty?
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
@empty [false, "", nil, [], 0, 0.0] | |
@spec empty?(any()) :: boolean() | |
def empty?(value) when value in @empty, do: true | |
def empty?(value) when is_list(value), do: Enum.all?(value, &empty?/1) | |
def empty?(value) when is_tuple(value), do: value |> Tuple.to_list() |> empty?() | |
def empty?(value) when is_struct(value), do: value |> Map.from_struct() |> empty?() | |
def empty?(value) when is_map(value), do: value |> Map.values() |> empty?() | |
def empty?(_), do: false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment