New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
janpieper opened this Issue Nov 19, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@janpieper
Contributor

janpieper commented Nov 19, 2018

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? 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment