The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.
use Test::More;
use strict; use warnings FATAL => 'all';

use List::Objects::WithUtils 'array';

my $arr = array( 1 .. 7 );
my $itr = $arr->natatime(3);
is_deeply [ $itr->() ], [1, 2, 3], 'natatime itr() 1 ok';
is_deeply [ $itr->() ], [4, 5, 6], 'natatime itr() 2 ok';
is_deeply [ $itr->() ], [7], 'natatime itr() 3 ok';
ok !$itr->(), 'last itr returned false';

my $counted;
$arr->natatime(3, sub { ++$counted });
is $counted, 3, 'natatime with coderef ok';

done_testing;