Skip to content

Instantly share code, notes, and snippets.

@zoffixznet

zoffixznet/p6.p6 Secret

Created March 29, 2017 17:41
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 zoffixznet/80955d554803d120ee95d68e0c8c7d3a to your computer and use it in GitHub Desktop.
Save zoffixznet/80955d554803d120ee95d68e0c8c7d3a to your computer and use it in GitHub Desktop.
class Wide { }
class Middle is Wide { }
class Narrow is Middle { }
subset Prime where .?is-prime;
subset NotPrime where not .?is-prime;
multi foo (Narrow $v) { say 'Narrow ', $v; 'from Narrow' }
multi foo (Middle $v) {
say 'Middle ', $v;
nextcallee;
my $result = callwith 42;
say "We're back! The return value is $result";
'from Middle'
}
multi foo (Wide $v) { say 'Wide ', $v; 'from Wide' }
multi foo (Prime $v) { say 'Prime ', $v; 'from Prime' }
multi foo (NotPrime $v) { say 'Non-Prime ', $v; 'from NotPrime' }
foo Middle;
# OUTPUT:
# Middle (Middle)
# Non-Prime 42
# We're back! The return value is from NotPrime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment