<commit_before>using System;

namespace Sawmill
{
    public static partial class Rewriter
    {
        /// <summary>
        /// Rebuild a tree by repeatedly applying a transformation function to every node in the tree,
        /// until <paramref name="transformer"/> returns <see cref="IterResult.Done{T}"/> for all nodes.
        /// (In other words, <c>rewriter.DescendantsAndSelf(rewriter.RewriteIter(f, x)).Any(n => f(n).Continue) == false</c>.)
        /// <para>
        /// This is typically useful when you want to put your tree into a normal form
        /// by applying a collection of rewrite rules until none of them can fire any more.
        /// </para>
        /// </summary>
        /// <typeparam name="T">The rewritable tree type</typeparam>
        /// <param name="rewriter">The rewriter</param>
        /// <param name="transformer">
        /// A transformation function to apply to every node in <paramref name="value"/> repeatedly until it returns <see cref="IterResult.Done{T}"/>.
        /// </param>
        /// <param name="value">The value to rewrite</param>
        /// <returns>
        /// The result of applying <paramref name="transformer"/> to every node in the tree
        /// represented by <paramref name="value"/> until it returns <see cref="IterResult.Done{T}"/>.
        /// </returns>
        public static T RewriteIter<T>(this IRewriter<T> rewriter, Func<T, IterResult<T>> transformer, T value) where T : class
        {
            if (rewriter == null)
            {
                throw new ArgumentNullException(nameof(rewriter));
            }
            if (transformer == null)
            {
                throw new ArgumentNullException(nameof(transformer));
            }

            Func<T, T> transformerDelegate = null;
            transformerDelegate = Transformer;
            T Transformer(T x)
            {
                var newX = transformer(x);
                if (newX.Continue)
                {
                    return Go(newX.Result);
                }
                return x;
            }
            T Go(T x) => rewriter.Rewrite(Transformer, x);
            return Go(value);
        }
    }
}<commit_msg>Save an allocation in RewriteIter<commit_after>using System;

namespace Sawmill
{
    public static partial class Rewriter
    {
        /// <summary>
        /// Rebuild a tree by repeatedly applying a transformation function to every node in the tree,
        /// until <paramref name="transformer"/> returns <see cref="IterResult.Done{T}"/> for all nodes.
        /// (In other words, <c>rewriter.DescendantsAndSelf(rewriter.RewriteIter(f, x)).Any(n => f(n).Continue) == false</c>.)
        /// <para>
        /// This is typically useful when you want to put your tree into a normal form
        /// by applying a collection of rewrite rules until none of them can fire any more.
        /// </para>
        /// </summary>
        /// <typeparam name="T">The rewritable tree type</typeparam>
        /// <param name="rewriter">The rewriter</param>
        /// <param name="transformer">
        /// A transformation function to apply to every node in <paramref name="value"/> repeatedly until it returns <see cref="IterResult.Done{T}"/>.
        /// </param>
        /// <param name="value">The value to rewrite</param>
        /// <returns>
        /// The result of applying <paramref name="transformer"/> to every node in the tree
        /// represented by <paramref name="value"/> until it returns <see cref="IterResult.Done{T}"/>.
        /// </returns>
        public static T RewriteIter<T>(this IRewriter<T> rewriter, Func<T, IterResult<T>> transformer, T value) where T : class
        {
            if (rewriter == null)
            {
                throw new ArgumentNullException(nameof(rewriter));
            }
            if (transformer == null)
            {
                throw new ArgumentNullException(nameof(transformer));
            }

            Func<T, T> transformerDelegate = null;
            transformerDelegate = Transformer;
            T Transformer(T x)
            {
                var newX = transformer(x);
                if (newX.Continue)
                {
                    return Go(newX.Result);
                }
                return x;
            }
            T Go(T x) => rewriter.Rewrite(transformerDelegate, x);
            return Go(value);
        }
    }
}
{'fraction_non_alphanumeric': 0.12182971014492754, 'fraction_numerical': 0.0, 'mean_word_length': 1.7973400886637112, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '794272', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1128, 'n_words': 366}