As an alternative to:

if foo(my_baz) and bar(my_baz) do
  # ...
end

it would be great to have `either` and `both` operators as sugar

if my_baz both foo and bar do
  # ...
end

if my_baz either foo or bar do
  # ...
end

These operators could be equivalent to the following function definitions

def both(_, true, true),      do: true
def both(_, false, _),        do: false
def both(_, _, false),        do: false
def both(value, true, right), do: right.(value)
def both(value, left, true),  do: left.(value)
def both(value, left, right) do
  left.(value) and right.(value)
end

def either(_, true, _),          do: true
def either(_, _, true),          do: true
def either(_, false, false),     do: false
def either(value, left, false),  do: left.(value)
def either(value, false, right), do: right.(value)
def either(value, left, right) do
  left.(value) or right.(value)
end

However, the support for boolean operands might not end up being the most 
readable.

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/0bae2cc5-a466-4f70-b069-878f594d45ef%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to