<commit_before># for our tantrums
my class X::TypeCheck { ... }
my class X::TypeCheck::Splice { ... }
my class X::Cannot::Lazy { ... }
my class X::Cannot::Empty { ... }
my class X::Immutable { ... }
my role Supply { ... }

my sub combinations(\n, \k) {
    return ((),) if k < 1;

    Seq.new(class :: does Iterator {
        has int $!n;
        has int $!k;
        has Mu $!stack;
        has Mu $!combination;
        method BUILD(\n,\k) {
            $!n = n;
            $!k = k;
            $!stack       := nqp::list(0);
            $!combination := nqp::list();
            self
        }
        method new(\n,\k) { nqp::create(self).BUILD(n,k) }

        method pull-one() {
            my int $n = $!n;
            my int $k = $!k;

            while nqp::elems($!stack) {
                my int $index = nqp::elems($!stack) - 1;
                my int $value = nqp::pop($!stack);

                while $value < $n && $index < $k {
                    nqp::bindpos($!combination,$index,+$value);
                    $index = $index + 1;
                    $value = $value + 1;
                    nqp::push($!stack,+$value);
                }
                return nqp::clone($!combination) if $index == $k;
            }
            IterationEnd
        }
    }.new(n,k))
}

# XXX This next function is only checked in to help 
#     debug a fairly insane bug.  It is not intended 
#     to be a long term part of rakudo.
sub very-broken-combinations($n, $k) {
    my @result;
    my $value = 1;

    gather for 0..4 {
        for 0..1 {
            @result[$_] = $value++;
        }
        take @result;
    }
}

my sub permutations(Int $n) {
    $n == 1 ?? ( (0,), ) !!
    gather for ^$n -> $i {
        my @i = flat 0 ..^ $i, $i ^..^ $n;
        for permutations($n - 1) {
            take ($i, |@i[@$_])
        }
    }
}

sub find-reducer-for-op($op) {
    try my %prec := $op.prec;
    return &METAOP_REDUCE_LEFT if (nqp::isnull(%prec) or ! %prec);
    my $reducer = %prec<prec> eq 'f='
        ?? 'listinfix'
        !! %prec<assoc> // 'left';
    ::('&METAOP_REDUCE_' ~ $reducer.uc);<commit_msg>Remove debug code (at least for the release)<commit_after># for our tantrums
my class X::TypeCheck { ... }
my class X::TypeCheck::Splice { ... }
my class X::Cannot::Lazy { ... }
my class X::Cannot::Empty { ... }
my class X::Immutable { ... }
my role Supply { ... }

my sub combinations(\n, \k) {
    return ((),) if k < 1;

    Seq.new(class :: does Iterator {
        has int $!n;
        has int $!k;
        has Mu $!stack;
        has Mu $!combination;
        method BUILD(\n,\k) {
            $!n = n;
            $!k = k;
            $!stack       := nqp::list(0);
            $!combination := nqp::list();
            self
        }
        method new(\n,\k) { nqp::create(self).BUILD(n,k) }

        method pull-one() {
            my int $n = $!n;
            my int $k = $!k;

            while nqp::elems($!stack) {
                my int $index = nqp::elems($!stack) - 1;
                my int $value = nqp::pop($!stack);

                while $value < $n && $index < $k {
                    nqp::bindpos($!combination,$index,+$value);
                    $index = $index + 1;
                    $value = $value + 1;
                    nqp::push($!stack,+$value);
                }
                return nqp::clone($!combination) if $index == $k;
            }
            IterationEnd
        }
    }.new(n,k))
}

my sub permutations(Int $n) {
    $n == 1 ?? ( (0,), ) !!
    gather for ^$n -> $i {
        my @i = flat 0 ..^ $i, $i ^..^ $n;
        for permutations($n - 1) {
            take ($i, |@i[@$_])
        }
    }
}

sub find-reducer-for-op($op) {
    try my %prec := $op.prec;
    return &METAOP_REDUCE_LEFT if (nqp::isnull(%prec) or ! %prec);
    my $reducer = %prec<prec> eq 'f='
        ?? 'listinfix'
        !! %prec<assoc> // 'left';
    ::('&METAOP_REDUCE_' ~ $reducer.uc);
{'fraction_non_alphanumeric': 0.1840833968980422, 'fraction_numerical': 0.005847953216374269, 'mean_word_length': 1.4993646759847523, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, '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': '1826228', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1349, 'n_words': 342}