flat
ErrorsCollection

flat

Synthesised documentation from type/Iterable type/independent-routines type/Supply type/Range type/Any type/Array type/Backtrace

From type/Iterable

See Original text in context

method flat(Iterable:D: --> Iterable)

Returns another Iterable that flattens out all iterables that the first one returns.

For example

say (<a b>'c').elems;         # OUTPUT: «2␤» 
say (<a b>'c').flat.elems;    # OUTPUT: «3␤»

because <a b> is a List and thus iterable, so (<a b>, 'c').flat returns ('a', 'b', 'c'), which has three elems.

Note that the flattening is recursive, so ((("a", "b"), "c"), "d").flat returns ("a", "b", "c", "d"), but it does not flatten itemized sublists:

say ($('a''b'), 'c').flat;    # OUTPUT: «($("a", "b"), "c")␤»

You can use the hyper method call to call the .List method on all the inner itemized sublists and so de-containerize them, so that flat can flatten them:

say ($('a''b'), 'c')>>.List.flat.elems;    # OUTPUT: «3␤»

From type/independent-routines

See Original text in context

multi flat(**@list)
multi flat(Iterable \a)

Constructs a list which contains any arguments provided, and returns the result of calling the .flat method (inherited from Any) on that list or Iterable:

say flat 1, (2, (34), $(56)); # OUTPUT: «(1 2 3 4 (5 6))␤»

From type/Supply

See Original text in context

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

Creates a supply on which all of the values seen in the given supply are flattened before being emitted again.

From type/Range

See Original text in context

method flat(Range:D:)

Generates a Seq containing the elements that the range represents.

From type/Any

See Original text in context

method flat() is nodal

Interprets the invocant as a list, flattens non-containerized Iterables into a flat list, and returns that list. Keep in mind Map and Hash types are Iterable and so will be flattened into lists of pairs.

say ((12), (3), %(:42a));      # OUTPUT: «((1 2) 3 {a => 42})␤» 
say ((12), (3), %(:42a)).flat# OUTPUT: «(1 2 3 a => 42)␤»

Note that Array containerize their elements by default, and so flat will not flatten them. You can use the

hyper method call to call the .List method on all the inner Iterable and so de-containerize them, so that flat can flatten them:

say [[123], [(45), 67]]      .flat# OUTPUT: «([1 2 3] [(4 5) 6 7])␤» 
say [[123], [(45), 67]]».List.flat# OUTPUT: «(1 2 3 4 5 6 7)␤»

For more fine-tuned options, see deepmap, duckmap, and signature destructuring

From type/Array

See Original text in context

multi method flat(Array:U:)
multi method flat(Array:D:)

This method will return the type object itself if it's applied to a type object; when applied to an object, it will return a Seq created from the array's underlying iterator.

my @a = <a 2 c>;
say @a.flat.^name# OUTPUT: «Seq␤» 

From type/Backtrace

See Original text in context

multi method flat(Backtrace:D:)

Returns the backtrace same as list.