Quick actions

cmd+k|ctrl+k

Navigation

Languages

How can I completely flatten a list (of lists (of lists) … )

Snippet info

Language

Raku

Visibility

public

Author

raiph.mellor

Created

2021-05-13T21:11:40.615872Z

Updated

2021-05-13T21:11:40.615872Z

my \Easily-Flattened-Lists = 1, (2, (3, 4)), 5..6, 7...8, $(9);

dd Easily-Flattened-Lists;       # (1, (2, (3, 4)), 5..6, 7, 8, 9).Seq
say flat Easily-Flattened-Lists; # (1 2 3 4 5 6 7 8 9)

my \Lists-With-Containers = 1, (2, [3, 4]), $(5..6), $(7...8), $[9];

sub more-flat (+@list) { gather @list.deepmap: *.take }

dd Lists-With-Containers;            # (1, [2, [3, 4]], 5..6, $((7, 8).Seq), $[9])
say more-flat Lists-With-Containers; # (1 2 3 4 5 6 7 8 9)

my \Captures-But-No-Attributes = 1, [2, [3, 4]], 5..6, $(7...8), $[9];

sub cowbell (+@list) { gather @list.deepmap: *.take }

dd Captures-But-No-Attributes;          # (1, [2, [3, 4]], 5..6, $((7, 8).Seq), $[9])
say cowbell Captures-But-No-Attributes; # (1 2 3 4 5 6 7 8 9)

my \Captures-And-Attributes = 1, [2, [3, 4]], 5..6, $(7...8), $[9];

sub more-cowbell (+@list) { gather @list.deepmap: *.take }

dd Captures-And-Attributes;               # (1, [2, [3, 4]], 5..6, $((7, 8).Seq), $[9])
say more-cowbell Captures-And-Attributes; # (1 2 3 4 5 6 7 8 9)
INFO