list
ErrorsCollection

list

Synthesised documentation from type/Buf type/Supply type/Range type/Blob type/Any type/Match type/Channel type/QuantHash type/Failure type/Backtrace type/Map type/PositionalBindFailover type/Capture type/Uni type/List

From type/Buf

See Original text in context

multi method list(Buf:D:)

Returns a List of integers.

say Buf.new(122,105,112,205).list# OUTPUT: «(122 105 112 205)␤»

From type/Supply

See Original text in context

multi method list(Supply:D:)

Taps the Supply it is called on, and returns a lazy list that will be reified as the Supply emits values. The list will be terminated once the Supply is done. If the Supply quits, then an exception will be thrown once that point in the lazy list is reached.

From type/Range

See Original text in context

multi method list(Range:D:)

Generates the list of elements that the range represents.

say (1..5).list;                                  # OUTPUT: «(1 2 3 4 5)␤» 
say (1^..^5).list;                                # OUTPUT: «(2 3 4)␤»

From type/Blob

See Original text in context

multi method list(Blob:D:)

Returns a List of integers:

say "zipi".encode("ascii").list# OUTPUT: «(122 105 112 105)␤»

From type/Any

See Original text in context

multi method list(Any:U:)
multi method list(Any:D \SELF:)

Applies the infix , operator to the invocant and returns the resulting Any:

say 42.list.^name;           # OUTPUT: «List␤» 
say 42.list.elems;           # OUTPUT: «1␤»

Subclasses of Any may choose to return any core type that does the Positional role from .list. Use .List to coerce specifically to Any.

@ can also be used as a list or Positional contextualizer:

my $not-a-list-yet = $[1,2,3];
say $not-a-list-yet.raku;             # OUTPUT: «$[1, 2, 3]␤» 
my @maybe-a-list = @$not-a-list-yet;
say @maybe-a-list.^name;              # OUTPUT: «Array␤» 

In the first case, the list is itemized. @ as a prefix puts the initial scalar in a list context by calling .list and turning it into an Array.

From type/Match

See Original text in context

Returns a list of positional submatches.

From type/Channel

See Original text in context

method list(Channel:D:)

Returns a list based on the Seq which will iterate items in the queue and remove each item from it as it iterates. This can only terminate once the close method has been called.

my $c = Channel.new$c.send(1); $c.send(2);
$c.close;
say $c.list# OUTPUT: «(1 2)␤»

From type/QuantHash

See Original text in context

multi method list(QuantHash:D:)

Returns a list of Pair objects of all keys and values in the QuantHash.

From type/Failure

See Original text in context

multi method list(Failure:D:)

Marks the failure as handled and throws the invocant's exception.

From type/Backtrace

See Original text in context

multi method list(Backtrace:D:)

Returns a list of Backtrace::Frame objects for this backtrace.

From type/Map

See Original text in context

multi method list(Map:D: --> List:D)

Returns a List of Pair objects of all keys and values in the Map.

my $m = Map.new('a' => (23), 'b' => 17);
say $m.list;                            # OUTPUT: «(b => 17 a => (2 3))␤»

From type/PositionalBindFailover

See Original text in context

multi method list(::?CLASS:D:)

Returns a List based on the iterator method without caching it.

From type/Capture

See Original text in context

method list(Capture:D:)

Returns the positional part of the Capture.

my Capture $c = \(235apples => (red => 2));
say $c.list# OUTPUT: «(2 3 5)␤»

From type/Uni

See Original text in context

method list(Uni:D:)

Returns a Seq of integer codepoints.

From type/List

See Original text in context

multi sub    list(+list)
multi method list(List:D:)

The method just returns the invocant self. The subroutine adheres to the single argument rule: if called with a single argument that is a non-itemized Iterable it returns a List based on the argument's iterator; otherwise it just returns the argument list.

For example:

my $tuple = (12);         # an itemized List 
put $tuple.list.raku;       # OUTPUT: «(1, 2)␤» 
put list($tuple).raku;      # OUTPUT: «($(1, 2),)␤» 
put list(|$tuple).raku;     # OUTPUT: «(1, 2)␤»

The last statement uses the prefix:<|> operator to flatten the tuple into an argument list, so it is equivalent to:

put list(12).raku;        # OUTPUT: «(1, 2)␤»

There are other ways to list the elements of an itemized single argument. For example, you can decontainerize the argument or use the @ list contextualizer:

put list($tuple<>).raku;    # OUTPUT: «(1, 2)␤» 
put list(@$tuple).raku;     # OUTPUT: «(1, 2)␤» 

Note that converting a type object to a list may not do what you expect:

put List.list.raku;         # OUTPUT: «(List,)␤»

This is because the .list candidate accepting a type object as the invocant is provided by Any. That candidate returns a list with one element: the type object self. If you're developing a collection type whose type object should be a valid representation of an empty collection, you may want to provide your own candidate for undefined invocants or override the Any: candidates with an "only" method. For example:

my class LinkedList {
    has $.value;            # the value stored in this node 
    has LinkedList $.next;  # undefined if there is no next node 
 
    method values--> Seq:D{
        my $node := self;
        gather while $node {
            take $node.value;
            $node := $node.next;
        }
    }
 
    method list--> List:D{
        self.values.list;
    }
}
 
my LinkedList $nodes;       # an empty linked list 
put $nodes.list.raku;       # OUTPUT: «()␤»