Skip to content

Commit

Permalink
Tidy up the functions in the Flag module
Browse files Browse the repository at this point in the history
  • Loading branch information
tompave committed Aug 7, 2024
1 parent 707e08b commit 5bdc072
Showing 1 changed file with 12 additions and 24 deletions.
36 changes: 12 additions & 24 deletions lib/fun_with_flags/flag.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,17 @@ defmodule FunWithFlags.Flag do
end


defp check_actor_gates(gates, item) do
gates
|> do_check_actor_gates(item)
end


defp do_check_actor_gates([], _), do: :ignore
defp check_actor_gates([], _), do: :ignore

defp do_check_actor_gates([%Gate{type: :actor} = gate | rest], item) do
defp check_actor_gates([%Gate{type: :actor} = gate | rest], item) do
case Gate.enabled?(gate, for: item) do
:ignore -> do_check_actor_gates(rest, item)
:ignore -> check_actor_gates(rest, item)
result -> result
end
end

defp do_check_actor_gates([_gate | rest], item) do
do_check_actor_gates(rest, item)
end


defp check_group_gates(gates, item) do
gates
|> do_check_group_gates(item)
defp check_actor_gates([_gate | rest], item) do
check_actor_gates(rest, item)
end


Expand All @@ -91,20 +79,20 @@ defmodule FunWithFlags.Flag do
# If a group gate is enabled, store the result but keep
# looping in case there is another group that is disabled.
#
defp do_check_group_gates(gates, item, result \\ :ignore)
defp check_group_gates(gates, item, result \\ :ignore)

defp do_check_group_gates([], _, result), do: result
defp check_group_gates([], _, result), do: result

defp do_check_group_gates([%Gate{type: :group} = gate|rest], item, temp_result) do
defp check_group_gates([%Gate{type: :group} = gate|rest], item, temp_result) do
case Gate.enabled?(gate, for: item) do
:ignore -> do_check_group_gates(rest, item, temp_result)
:ignore -> check_group_gates(rest, item, temp_result)
{:ok, false} -> {:ok, false}
{:ok, true} -> do_check_group_gates(rest, item, {:ok, true})
{:ok, true} -> check_group_gates(rest, item, {:ok, true})
end
end

defp do_check_group_gates([_gate | rest], item, temp_result) do
do_check_group_gates(rest, item, temp_result)
defp check_group_gates([_gate | rest], item, temp_result) do
check_group_gates(rest, item, temp_result)
end


Expand Down

0 comments on commit 5bdc072

Please sign in to comment.