alexocode/brex

`Brex.none/1` misbehaves when an empty list of rules is given

Closed this issue · 0 comments

When using Brex.none/1 with a dynamic set of rules, I discovered a behaviour I am unsure if it is the expected one. Check the following example:

Brex.none([])
|> Brex.evaluate(:something)
|> Brex.passed?()

No rules have been passed to Brex.none/1. I would expect true, but it currently returns false.

There is no native implementation of none? in Elixir, so I use Ruby as reference:

[].all?  # true
[].none? # true

The problem with Brex.none/1 and passing an empty list of rules is, that it passes the given rules to Brex.all/1 and inverts the result. I think we need a special handling for the case when Brex.none/1 receives an empty list of rules.

defmodule Brex.Operator.Aggregator do
  # ...

  def none?([]), do: true
  def none?(enum), do: not all?(enum)
end

What do you think? 😉