Skip to content

Instantly share code, notes, and snippets.

@pragdave
Last active August 29, 2015 13:59
Show Gist options
  • Save pragdave/10761501 to your computer and use it in GitHub Desktop.
Save pragdave/10761501 to your computer and use it in GitHub Desktop.
defmodule Bitmap do
defstruct value: 0
end
defimpl Access, for: Bitmap do
use Bitwise
def access(%Bitmap{value: value}, bit) do
if (value &&& (1 <<< bit)) == 0, do: 0, else: 1
end
end
fifty = %Bitmap{value: 50}
[5,4,3,2,1,0] |> Enum.each(fn bit -> IO.puts fifty[bit] end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment