Skip to content

Commit

Permalink
remove Zipper.reduce/3 - bugged, but more importantly unused
Browse files Browse the repository at this point in the history
  • Loading branch information
novaugust committed Nov 27, 2024
1 parent d35a28d commit 98c5c1c
Showing 1 changed file with 0 additions and 20 deletions.
20 changes: 0 additions & 20 deletions lib/zipper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -317,26 +317,6 @@ defmodule Styler.Zipper do
if next = next(zipper), do: do_traverse(next, acc, fun), else: {top(zipper), acc}
end

@doc """
Same as `traverse/3`, but doesn't waste cycles going back to the top of the tree when traversal is finished
Useful when only the accumulator is of interest, and no updates to the zipper are.
"""
@spec reduce(zipper, term, (zipper, term -> {zipper, term})) :: term
def reduce({_, nil} = zipper, acc, fun) do
do_reduce(zipper, acc, fun)
end

def reduce({tree, meta}, acc, fun) do
{{updated, _meta}, acc} = do_reduce({tree, nil}, acc, fun)
{{updated, meta}, acc}
end

defp do_reduce(zipper, acc, fun) do
{zipper, acc} = fun.(zipper, acc)
if next = next(zipper), do: do_reduce(next, acc, fun), else: acc
end

@doc """
Traverses the tree in depth-first pre-order calling the given function for
each node.
Expand Down

0 comments on commit 98c5c1c

Please sign in to comment.