### ----------------------------------------------------
### -- Iter::Able
### -- Licenses: Artistic-2.0
### -- Authors: 
### -- File: t/09-map-first.rakutest
### ----------------------------------------------------
use Test;
use Iter::Able::Map-First;

my &id = -> \g, \e, Str $desc? { g | e ~~ Seq:D ?? cmp-ok(g, "eqv", e, $desc) !! is-deeply(g, e, $desc) };

plan 10;

my $s;
$s := [1, 2, 3];
id map-first($s, * > 0, -*), (-1, 2, 3).Seq, "Random list with `* > 0` and `-*`";

$s := [4, 44, 444, 4444];
id $s.&map-first(*.is-prime, { 7 }), $s.Seq, "Random list with no match";

$s := [];
id map-first($s, {;}, {;}), [].Seq,  "Empty-list";

$s := [5, 6, 7].Seq;
id $s.&map-first({ True }, { 0 }), (0, 6, 7).Seq, "Seq with all-pass filter";

$s := [5, 6, 7];
id $s.&map-first({ False }, { 0 }), $s.Seq, "Random list with no-pass filter";

$s := "here WE are";
id $s.&map-first(/ <.upper> /, &lc),  "here wE are", "Mixed case string with \"lower the first upper\"";

$s := (0, -2, -7, 5, 12, 13);
my \it = $s.iterator;
it.pull-one for ^2;
my \newit = map-first(it, * %% 3, * ** 2);
it.pull-one;  # should affect `newit`s behaviour
does-ok newit, Iterator, "Iterator (returned an Iterator, not a Seq)";
id Seq.new(newit), [5, 144, 13].Seq, "Iterator (values)";
ok it.pull-one =:= IterationEnd, "Iterator (original, exhausted)";
ok newit.pull-one =:= IterationEnd, "Iterator (new, exhausted)";

done-testing;


