Skip to content

Instantly share code, notes, and snippets.

@dogbert17
Created July 16, 2016 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dogbert17/dcf078ff80c7b868dfdce95632b4ad63 to your computer and use it in GitHub Desktop.
Save dogbert17/dcf078ff80c7b868dfdce95632b4ad63 to your computer and use it in GitHub Desktop.
# enable wrapping:
use soft;
# function to be wrapped:
sub square-root($x) { $x.sqrt }
&square-root.wrap(-> $num {
nextsame if $num >= 0;
1i * callwith(abs($num));
});
say square-root(4); # 2
say square-root(-4); # 0+2i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment