Skip to content

Instantly share code, notes, and snippets.

@tobyink
Last active September 25, 2020 21:22
Embed
What would you like to do?
Linked lists, Zydeco example
package SLL {
use Zydeco;
class Node {
has value ( type => Int );
has nextnode ( type => Maybe[Object] );
method printvalue () {
print $self->value, " ";
}
method go_next = $self->nextnode;
factory new_node ( Int $value, Object $next? ) {
return $class->new(
value => $value,
nextnode => $next
);
}
}
}
my $node_a = SLL->new_node(30);
my $node_b = SLL->new_node(40, $node_a);
my $node_c = SLL->new_node(70, $node_b);
my $node_head = SLL->new_node(0, $node_c);
my $node = $node_head;
while ( $node = $node->go_next ) {
$node->printvalue;
}
print "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment