Skip to content

Commit

Permalink
fix: have filter take a var decl instead of a bare name
Browse files Browse the repository at this point in the history
  • Loading branch information
ulfurinn committed May 16, 2024
1 parent 7cdf71e commit a79b8e5
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/wongi/engine/dsl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
4 changes: 3 additions & 1 deletion lib/wongi/engine/filter/function.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion test/wongi/engine/filter/function_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]
)
)
Expand Down

0 comments on commit a79b8e5

Please sign in to comment.