EEP 70: Non-filtering generators

What happens when the filter expression does not evaluate to a boolean value depends on the expression:

  • If the expression is a guard expression, failure to evaluate or evaluating to a non-boolean value is equivalent to evaluating to false.
  • If the expression is not a guard expression and evaluates to a non-Boolean value Val, an exception {bad_filter, Val} is triggered at runtime. If the evaluation of the expression raises an exception, it is not caught by the comprehension.

Erlang reference manual describes the expected behaviors for filters in comprehensions quite accurately imo. If the expression is considered a guard, it doesn’t raise an exception, which is consistent with how guards are dealt with elsewhere.

4 Likes