Hi everyone in this list,

I hope it has a good reception among the community, since it has the
potential to change the way we write functions guards in a very positive
and more natural way.

Guards clauses are a key feature in Elixir. Researching
how to make it easier for developers to define guards, has led me to
two enhancement proposal. This is the first one, which will allow
developers to write guards, guard safe macros and other clauses in a
more natural and succinct way.

All the following macros are allowed in guards:
- `is_kind(term, kind)` determines if a given `term` is of a certain
  `kind`.
- `term is kinds` determines if `term` is each kind in `kinds`.
- `term is_not kinds` determines if `term` is not of any of the `kinds`.
- `term is_any kinds` determines if `term` is of any of the `kinds`.
- `terms are kinds` determines if every term in list `terms` is of
  every kind in `kinds`.
- `terms are_not kinds` determines if every item in list `terms` is not
  of `kind`.
- `terms are_any kinds` determines if every term in list `terms` is not
  of any of the `kinds`.

Allowing us to write functions guards as regular code, that otherwise
it would take a really long lines of code:

  def check(letter) when letter is :char, do: true

  iex> [100, 200] are [:even, {:>=, 100}]
  true

write expressions in a more natural way:
  iex> term is_not nil

as opposed to
  iex> not is_nil(term)

For a list of all supported kinds, see the list:
https://gist.github.com/eksperimental/a6df4348e9675109e49ccf4e34101bfe#list-of-supported-kinds-by-is_kind2

Here's the proposal:
https://gist.github.com/eksperimental/a6df4348e9675109e49ccf4e34101bfe

and here the its full implementation:
https://github.com/eksperimental/elixir/tree/is-kind

Looking forwards to hear your opinions

-- 
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/20160811223043.7a17eb02.eksperimental%40autistici.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to