Hi

What would this add to the language that we don't already have? It seems to
overlap with &&, ||, and, or, Enum.any, and Enum.all. I would rather we
have fewer ways in the standard library to write the same thing, rather
than more, so new people coming to this language have less special cases,
syntaxes and rules to learn.

This could be implemented today as a macro quite easily. Perhaps make a hex
package for this as then people can use this if they wish and we don't have
to modify the standard library and wait for another Elixir released.

Cheers,
Louis

On Fri, 2 Mar 2018, 05:55 Daniel Angell, <supa.coo....@gmail.com> wrote:

> 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 elixir-lang-core+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/0bae2cc5-a466-4f70-b069-878f594d45ef%40googlegroups.com
> <https://groups.google.com/d/msgid/elixir-lang-core/0bae2cc5-a466-4f70-b069-878f594d45ef%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CABu8xFBpm5TfM59g9%3Db62fVs3%3DTTcXrakXDiAbfUxTrtRm%3D%2BRw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to