The Capture routine

Combined from primary sources listed below.

In class Map ( Type/Map )§

See primary docmentation in context for method Capture.

method Capture§

method Capture(Map:D:)

Returns a Capture where each key, if any, has been converted to a named argument with the same value as it had in the original Map. The returned Capture will not contain any positional arguments.

my $map = Map.new('a' => 2, 'b' => 17);
my $capture = $map.Capture;
my-sub(|$capture);                                # OUTPUT: «2, 17␤»

sub my-sub(:$a, :$b) {
    say "$a, $b"
}

In class Str ( Type/Str )§

See primary docmentation in context for method Capture.

method Capture§

method Capture()

Throws X::Cannot::Capture.

In role Callable ( Type/Callable )§

See primary docmentation in context for method Capture.

method Capture§

method Capture()

Throws X::Cannot::Capture.

In class Channel ( Type/Channel )§

See primary docmentation in context for method Capture.

method Capture§

method Capture(Channel:D: --> Capture:D)

Equivalent to calling .List.Capture on the invocant.

In class RatStr ( Type/RatStr )§

See primary docmentation in context for method Capture.

method Capture§

method Capture(RatStr:D: --> Capture:D)

Equivalent to Mu.Capture.

In class Seq ( Type/Seq )§

See primary docmentation in context for method Capture.

method Capture§

method Capture()

Coerces the object to a List, which is in turn coerced into a Capture.

In class Supply ( Type/Supply )§

See primary docmentation in context for method Capture.

method Capture§

method Capture(Supply:D: --> Capture:D)

Equivalent to calling .List.Capture on the invocant.

In class Version ( Type/Version )§

See primary docmentation in context for method Capture.

method Capture§

method Capture()

Throws X::Cannot::Capture.

In class List ( Type/List )§

See primary docmentation in context for method Capture.

method Capture§

method Capture(List:D: --> Capture:D)

Returns a Capture where each Pair, if any, in the <List has been converted to a named argument (with the key of the Pair stringified). All other elements in the List are converted to positional arguments in the order they are found, i.e. the first non pair item in the list becomes the first positional argument, which gets index 0, the second non pair item becomes the second positional argument, getting index 1 etc.

my $list = (7, 5, a => 2, b => 17);
my $capture = $list.Capture;
say $capture.keys;                                # OUTPUT: «(0 1 a b)␤»
my-sub(|$capture);                                # OUTPUT: «7, 5, 2, 17␤»

sub my-sub($first, $second, :$a, :$b) {
    say "$first, $second, $a, $b"
}

A more advanced example demonstrating the returned Capture being matched against a Signature.

my $list = (7, 5, a => 2, b => 17);
say so $list.Capture ~~ :($ where * == 7,$,:$a,:$b); # OUTPUT: «True␤»

$list = (8, 5, a => 2, b => 17);
say so $list.Capture ~~ :($ where * == 7,$,:$a,:$b); # OUTPUT: «False␤»

In class Whatever ( Type/Whatever )§

See primary docmentation in context for method Capture.

method Capture§

method Capture()

Throws X::Cannot::Capture.

In class Int ( Type/Int )§

See primary docmentation in context for method Capture.

method Capture§

method Capture()

Throws X::Cannot::Capture.

In class Range ( Type/Range )§

See primary docmentation in context for method Capture.

method Capture§

method Capture(Range:D: --> Capture:D)

Returns a Capture with values of .min .max, .excludes-min, .excludes-max, .infinite, and .is-int as named arguments.

In role Blob ( Type/Blob )§

See primary docmentation in context for method Capture.

method Capture§

method Capture(Blob:D:)

Converts the object to a List which is, in turn, coerced to a Capture.

In class ComplexStr ( Type/ComplexStr )§

See primary docmentation in context for method Capture.

method Capture§

method Capture(ComplexStr:D: --> Capture:D)

Equivalent to Mu.Capture.

In class Mu ( Type/Mu )§

See primary docmentation in context for method Capture.

method Capture§

method Capture(Mu:D: --> Capture:D)

Returns a Capture with named arguments corresponding to invocant's public attributes:

class Foo {
    has $.foo = 42;
    has $.bar = 70;
    method bar { 'something else' }
}.new.Capture.say# OUTPUT: «\(:bar("something else"), :foo(42))␤»

In class Capture ( Type/Capture )§

See primary docmentation in context for method Capture.

method Capture§

method Capture(Capture:D: --> Capture:D)

Returns itself, i.e. the invocant.

say \(1,2,3, apples => 2).Capture# OUTPUT: «\(1, 2, 3, :apples(2))␤»

In role QuantHash ( Type/QuantHash )§

See primary docmentation in context for method Capture.

method Capture§

method Capture()

Returns the object as a Capture by previously coercing it to a Hash.

In class Failure ( Type/Failure )§

See primary docmentation in context for method Capture.

method Capture§

method Capture()

Throws X::Cannot::Capture if the invocant is a type object or a handled Failure. Otherwise, throws the invocant's exception.

In class Num ( Type/Num )§

See primary docmentation in context for method Capture.

method Capture§

method Capture()

Throws X::Cannot::Capture.

In class Signature ( Type/Signature )§

See primary docmentation in context for method Capture.

method Capture§

method Capture()

Throws X::Cannot::Capture.