<commit_before>use v6;
use Test;

# L<S03/List infix precedence/"the series operator">

plan 40;

# some tests firsts that don't require lazy lists

#?rakudo skip 'dispatch'
{
    # arity 1
    my @a = 1...{ $_ >= 3 ?? () !! $_ + 1 };
    is @a.join(', '), '1, 2, 3';
}

{
    # arity 2
    # http://www.perlmonks.org/?node_id=772778
    sub gcd ($a, $b) {
        ($a, $b ... { $^x % $^y || () })[*-1]
    }
    is gcd(2, 1), 1, 'gcd with infix:<...> (1)';
    is gcd(42, 24), 6, 'gcd with infix:<...> (2)';
}

#?rakudo skip 'lazy lists'
{
    my @fib = 1, 1 ... {$^x + $^y};
    is @fib[0], 1, 'fibonacci generator with series op works (0)';
    is @fib[1], 1, 'fibonacci generator with series op works (1)';
    is @fib[2], 2, 'fibonacci generator with series op works (2)';
    is @fib[3], 3, 'fibonacci generator with series op works (3)';
    is @fib[4], 5, 'fibonacci generator with series op works (4)';
    is @fib[5], 8, 'fibonacci generator with series op works (5)';
}

#?rakudo skip 'lazy lists'
{
    my @fib = 1, 1 ... &infix:<+>;
    is @fib[0], 1, 'fibonacci generator with series op works (0)';
    is @fib[1], 1, 'fibonacci generator with series op works (1)';
    is @fib[2], 2, 'fibonacci generator with series op works (2)';
    is @fib[3], 3, 'fibonacci generator with series op works (3)';
    is @fib[4], 5, 'fibonacci generator with series op works (4)';
    is @fib[5], 8, 'fibonacci generator with series op works (5)';<commit_msg>[t/spec] slurpy generator for series, eternaleye++<commit_after>use v6;
use Test;

# L<S03/List infix precedence/"the series operator">

plan 46;

# some tests firsts that don't require lazy lists

#?rakudo skip 'dispatch'
{
    # arity 1
    my @a = 1...{ $_ >= 3 ?? () !! $_ + 1 };
    is @a.join(', '), '1, 2, 3';
}

{
    # arity 2
    # http://www.perlmonks.org/?node_id=772778
    sub gcd ($a, $b) {
        ($a, $b ... { $^x % $^y || () })[*-1]
    }
    is gcd(2, 1), 1, 'gcd with infix:<...> (1)';
    is gcd(42, 24), 6, 'gcd with infix:<...> (2)';
}

{
    # slurpy
	sub nextprime( *@prev_primes ) {
        state $iterations = 0;
		return () if $iterations > 3;
		++$iterations;
		my $current = @prev_primes[*-1];
		while ++$current {
            return $current if $current % all(@prev_primes) != 0;
        }
    }
    my @seed = 2, 3;
	my @primes = @seed ... &nextprime;
	is @primes[0], 2, 'prime generator with series op works (0)';
	is @primes[1], 3, 'prime generator with series op works (0)';
	is @primes[2], 5, 'prime generator with series op works (0)';
	is @primes[3], 7, 'prime generator with series op works (0)';
	is @primes[4], 11, 'prime generator with series op works (0)';
	is @primes[5], 13, 'prime generator with series op works (0)';
}

#?rakudo skip 'lazy lists'
{
    my @fib = 1, 1 ... {$^x + $^y};
    is @fib[0], 1, 'fibonacci generator with series op works (0)';
    is @fib[1], 1, 'fibonacci generator with series op works (1)';
    is @fib[2], 2, 'fibonacci generator with series op works (2)';
    is @fib[3], 3, 'fibonacci generator with series op works (3)';
    is @fib[4], 5, 'fibonacci generator with series op works (4)';
    is @fib[5], 8, 'fibonacci generator with series op works (5)';
}

#?rakudo skip 'lazy lists'
{
    my @fib = 1, 1 ... &infix:<+>;
    is @fib[0], 1, 'fibonacci generator with series op works (0)';
    is @fib[1], 1, 'fibonacci generator with series op works (1)';
    is @fib[2], 2, 'fibonacci generator with series op works (2)';
    is @fib[3], 3, 'fibonacci generator with series op works (3)';
    is @fib[4], 5, 'fibonacci generator with series op works (4)';
    is @fib[5], 8, 'fibonacci generator with series op works (5)';
{'fraction_non_alphanumeric': 0.18869470234844346, 'fraction_numerical': 0.04533042053522665, 'mean_word_length': 3.0164473684210527, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6849379', 'n_tokens_mistral': 1564, 'n_tokens_neox': 1403, 'n_words': 497}