diff --git a/lib/wongi/engine/dsl.ex b/lib/wongi/engine/dsl.ex index 08f2eb8..cafef5f 100644 --- a/lib/wongi/engine/dsl.ex +++ b/lib/wongi/engine/dsl.ex @@ -137,7 +137,7 @@ defmodule Wongi.Engine.DSL do @doc """ A filter that passes if the value is a unary function that returns true. - The function will receive the variable as its argument. + The function will receive the variable value as its argument. """ def filter(var, func), do: Filter.new(Function.new(var, func)) diff --git a/lib/wongi/engine/filter/function.ex b/lib/wongi/engine/filter/function.ex index 366c71e..b6676cc 100644 --- a/lib/wongi/engine/filter/function.ex +++ b/lib/wongi/engine/filter/function.ex @@ -11,6 +11,8 @@ defmodule Wongi.Engine.Filter.Function do end defimpl Wongi.Engine.Filter do + alias Wongi.Engine.Filter.Common + def pass?(%@for{var: nil, func: func}, _token) when is_function(func, 0) do func.() end @@ -20,7 +22,7 @@ defmodule Wongi.Engine.Filter.Function do end def pass?(%@for{var: var, func: func}, token) when is_function(func, 1) do - func.(token[var]) + func.(Common.resolve(var, token)) end end end diff --git a/mix.exs b/mix.exs index 4ad091c..4f44f94 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Wongi.Engine.MixProject do def project do [ app: :wongi_engine, - version: "0.9.13", + version: "0.9.14", elixir: "~> 1.15", elixirc_paths: elixirc_paths(Mix.env()), start_permanent: Mix.env() == :prod, diff --git a/test/wongi/engine/filter/function_test.exs b/test/wongi/engine/filter/function_test.exs index dede23b..eb86b3c 100644 --- a/test/wongi/engine/filter/function_test.exs +++ b/test/wongi/engine/filter/function_test.exs @@ -40,7 +40,7 @@ defmodule Wongi.Engine.Filter.FunctionTest do rule( forall: [ has(:a, :b, var(:x)), - filter(:x, &__MODULE__.true?/1) + filter(var(:x), &__MODULE__.true?/1) ] ) )