Created
October 26, 2018 16:46
-
-
Save shdblowers/51fec760a7d4870d145065a8f8a5a010 to your computer and use it in GitHub Desktop.
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
defprotocol Size do | |
@doc "Calculates the size (and not the length!) of a data structure" | |
def size(data) | |
end | |
defimpl Size, for: BitString do | |
def size(string), do: byte_size(string) | |
end | |
defimpl Size, for: Map do | |
def size(map), do: map_size(map) | |
end | |
defimpl Size, for: Tuple do | |
def size(tuple), do: tuple_size(tuple) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment