Skip to content

Instantly share code, notes, and snippets.

@marcoonroad
Created October 22, 2014 17:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcoonroad/6fea8b16953bc368123d to your computer and use it in GitHub Desktop.
Save marcoonroad/6fea8b16953bc368123d to your computer and use it in GitHub Desktop.
Linked/chained list generator multi-dispatch function written at Perl6.
#!/usr/bin/perl6
use v6;
multi chain ([ ]) { [ head => [ ] ] }
multi chain (@Ls) { [ head => @Ls.shift, tail => chain @Ls ] }
# test
my @chained = chain [ 1, 2, 3 ];
say @chained.perl;
# Array.new(["head" => 1, "tail" => ["head" => 2, "tail" => ["head" => 3, "tail" => ["head" => []]]]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment