Skip to content

Instantly share code, notes, and snippets.

@jjn1056
Created July 7, 2010 13:04
Show Gist options
  • Save jjn1056/466660 to your computer and use it in GitHub Desktop.
Save jjn1056/466660 to your computer and use it in GitHub Desktop.
subtype PStr,
as Parameterizable[Str, Int),
where { length(shift) < shift) };
method(Int $length = 10)
my_name(PStr[$length] $name)
{
return "Hello $name!";
}
say $self->my_name->with(5)->('JohnN');
say $self->my_name(10,'JohnN'); ## "Hello JohnN!"
say $self->my_name(2,'JohnN'); ## dies with constraint violation
my $cb = $self->my_name(10);
say $self->$cb('JohnN'); ## "Hello JohnN!"
subtype UniqueID,
as Parameterizable[Int, ResultSet],
where { ! $_->[1]->find($_->[0]) };
method(Object $rs = sub {shift->rs} )
my_name(UniqueID[$rs] $id)
{
## Something
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment