Skip to content

Commit

Permalink
Merge pull request #6 from am-kantox/#4-tests-from-core-for-for
Browse files Browse the repository at this point in the history
#4 tests from core for for
  • Loading branch information
Aleksei Matiushkin authored Sep 18, 2019
2 parents 7f36ded + 3122b0d commit a05d8a0
Show file tree
Hide file tree
Showing 3 changed files with 569 additions and 5 deletions.
18 changes: 14 additions & 4 deletions lib/lazy_for.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ defmodule LazyFor do
defp clause({:<-, _meta, [var, source]}, inner, acc),
do: do_stransf_clause(source, acc, do_fn_body([inner], var))

# expression
defp clause({:=, meta, [var, expression]}, inner, acc),
do: clause({:<-, meta, [var, [expression]]}, inner, acc)

# condition
defp clause(guard, {__s__(), _, _} = inner, _acc),
do: {sfilter(), [], [inner, {:fn, [], [{:->, [], [[{:_, [], Elixir}], guard]}]}]}
Expand All @@ -82,14 +86,20 @@ defmodule LazyFor do
defp do_stransf_clause(source, acc, fn_body),
do: {stransf(), [], [source, acc, {:fn, [], fn_body}]}

defp do_fn_body(inner, var), do: [{:->, [], [[var, a()], {inner, a()}]}]
defp do_fn_body(inner, {var_name, _, ctx} = var) when is_atom(var_name) and is_atom(ctx),
do: [{:->, [], [[var, a()], {inner, a()}]}]

defp do_fn_body(inner, var, conditions) do
[
defp do_fn_body(inner, var),
do: [
{:->, [], [[var, a()], {inner, a()}]},
{:->, [], [[{:_, [], Elixir}, a()], {[], a()}]}
]

defp do_fn_body(inner, var, conditions),
do: [
{:->, [], [[{:when, [], [var, a(), conditions]}], {inner, a()}]},
{:->, [], [[{:_, [], Elixir}, a()], {[], a()}]}
]
end

##############################################################################

Expand Down
Loading

0 comments on commit a05d8a0

Please sign in to comment.