<commit_before>use v6;
use Test;

# L<S29/"List"/"=item first">

=begin pod

built-in "first" tests

=end pod

plan 9;

my @list = (1 .. 10);

{
    my $result = first { ($_ % 2) }, @list;
    ok($result ~~ Item, "first() returns an Item");
    is($result, 1, "returned value by first() is correct");
}

{
    my $result = @list.first( { ($_ == 4)});
    ok($result ~~ Item, "method form of first returns an item");
    is($result, 4, "method form of first returns the expected item");
}

#?rakudo skip "colon invocant syntax"
{
    my $result = @list.first():{ ($_ == 4) };
    ok($result ~~ Item, "first():<block> returns an Item");
    is($result, 4, "first() returned the expected value");
}

{
	is(@list.first( { ($_ == 11) }), undef, 'first returns undef unsuccessfull match');
}

{
	my $count = 0;
	my $matcher = sub (Num $x) { $count++; return $x % 2 };
	is(@list.first($matcher), 1, 'first() search for odd elements successfull');
	is($count, 1, 'Matching closure in first() is only executed once');

}<commit_msg>[spec] Replace ~~Item with ~~Int.<commit_after>use v6;
use Test;

# L<S29/"List"/"=item first">

=begin pod

built-in "first" tests

=end pod

plan 9;

my @list = (1 .. 10);

{
    my $result = first { ($_ % 2) }, @list;
    ok($result ~~ Int, "first() returns an Int");
    is($result, 1, "returned value by first() is correct");
}

{
    my $result = @list.first( { ($_ == 4)});
    ok($result ~~ Int, "method form of first returns an Int");
    is($result, 4, "method form of first returns the expected item");
}

#?rakudo skip "colon invocant syntax"
{
    my $result = @list.first():{ ($_ == 4) };
    ok($result ~~ Int, "first():<block> returns an Int");
    is($result, 4, "first() returned the expected value");
}

{
	is(@list.first( { ($_ == 11) }), undef, 'first returns undef unsuccessfull match');
}

{
	my $count = 0;
	my $matcher = sub (Int $x) { $count++; $x % 2 };
	is(@list.first($matcher), 1, 'first() search for odd elements successfull');
	is($count, 1, 'Matching closure in first() is only executed once');

}
{'fraction_non_alphanumeric': 0.2011690209449586, 'fraction_numerical': 0.018509498295177788, 'mean_word_length': 3.6157303370786518, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '6152110', 'n_tokens_mistral': 767, 'n_tokens_neox': 733, 'n_words': 245}