Skip to content

Instantly share code, notes, and snippets.

@shdblowers
Created October 26, 2018 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shdblowers/51fec760a7d4870d145065a8f8a5a010 to your computer and use it in GitHub Desktop.
Save shdblowers/51fec760a7d4870d145065a8f8a5a010 to your computer and use it in GitHub Desktop.
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