@@ -317,8 +317,11 @@ defmodule Styler.Zipper do
317
317
if next = next ( zipper ) , do: do_traverse ( next , acc , fun ) , else: { top ( zipper ) , acc }
318
318
end
319
319
320
- # Same as `traverse/3`, but doesn't waste cycles going back to the top of the tree when traversal is finished
321
- @ doc false
320
+ @ doc """
321
+ Same as `traverse/3`, but doesn't waste cycles going back to the top of the tree when traversal is finished
322
+
323
+ Useful when only the accumulator is of interest, and no updates to the zipper are.
324
+ """
322
325
@ spec reduce ( zipper , term , ( zipper , term -> { zipper , term } ) ) :: term
323
326
def reduce ( { _ , nil } = zipper , acc , fun ) do
324
327
do_reduce ( zipper , acc , fun )
@@ -390,17 +393,14 @@ defmodule Styler.Zipper do
390
393
end
391
394
end
392
395
393
- @ doc false
394
- # Similar to traverse_while/3, but returns the `acc` directly, skipping the return to the top of the zipper.
395
- # For that reason the :halt tuple is instead just a 2-ple of `{:halt, acc}`
396
- @ spec reduce_while ( zipper , term , ( zipper , term -> { command , zipper , term } ) ) :: { zipper , term }
397
- def reduce_while ( { _tree , nil } = zipper , acc , fun ) do
398
- do_reduce_while ( zipper , acc , fun )
399
- end
396
+ @ doc """
397
+ Same as `traverse_while/3` except it only returns the acc, saving the work of returning to the top of the zipper.
400
398
401
- def reduce_while ( { tree , meta } , acc , fun ) do
402
- { { updated , _meta } , acc } = do_reduce_while ( { tree , nil } , acc , fun )
403
- { { updated , meta } , acc }
399
+ For that reason the `:halt` tuple is instead just a 2-ple of `{:halt, acc}`
400
+ """
401
+ @ spec reduce_while ( zipper , term , ( zipper , term -> { :cont | :skip , zipper , term } | { :halt , term } ) ) :: term
402
+ def reduce_while ( { tree , _meta } , acc , fun ) do
403
+ do_reduce_while ( { tree , nil } , acc , fun )
404
404
end
405
405
406
406
defp do_reduce_while ( zipper , acc , fun ) do
0 commit comments