Skip to content

Instantly share code, notes, and snippets.

@tvon
Last active December 23, 2015 17:16
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 tvon/af32f434124320e97b31 to your computer and use it in GitHub Desktop.
Save tvon/af32f434124320e97b31 to your computer and use it in GitHub Desktop.
flags = %{
default: 0,
sourcepos: 1,
hardbreaks: 2,
normalize: 4,
smart: 8,
validate_utf8: 16,
safe: 32
}
options = [
sourcepos: false,
safe: false,
smart: true, # 8
hardbreaks: true # 2
]
# Finding the correct values works
for {enabled, true} <- options, value = flags[enabled], do: IO.puts "#{enabled}: #{value}"
# [2, 8]
# Gives correct result but seems inelegant
values = for {enabled, true} <- options, value = flags[enabled], do: value
use Bitwise
Enum.reduce(values, fn(x, acc) -> x ||| acc end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment