eager
ErrorsCollection

eager

Synthesised documentation from type/Any type/Sequence type/List

From type/Any

See Original text in context

method eager() is nodal

Interprets the invocant as a Any, evaluates it eagerly, and returns that Any.

my  $range = 1..5;
say $range;         # OUTPUT: «1..5␤» 
say $range.eager;   # OUTPUT: «(1 2 3 4 5)␤»

From type/Sequence

See Original text in context

method eager(::?CLASS:D: --> List:D)

Returns an eagerly evaluated List based on the invocant sequence, and marks it as consumed. If called on an already consumed Seq, throws an error of type X::Seq::Consumed.

my $s = lazy 1..5;
 
say $s.is-lazy# OUTPUT: «True␤» 
say $s.eager;   # OUTPUT: «(1 2 3 4 5)␤» 
 
say $s.eager;
CATCH {
    when X::Seq::Consumed {
        say 'Throws exception if already consumed';
    }
}
# OUTPUT: «Throws exception if already consumed␤»

From type/List

See Original text in context

multi method eager(List:D: --> List:D)

Evaluates all elements in the List eagerly, and returns them as a List.

my  \ll = (lazy 1..5).cache;
 
say ll[];     # OUTPUT: «(...)␤» 
say ll.eager  # OUTPUT: «(1 2 3 4 5)␤»