Created
October 22, 2014 17:32
-
-
Save marcoonroad/6fea8b16953bc368123d to your computer and use it in GitHub Desktop.
Linked/chained list generator multi-dispatch function written at Perl6.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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