Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 31 lines (20 sloc) 0.923 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
SYNOPSIS

    use Typed::Subroutines;

    # create a subtype from Sub
    subset TwoArgSub of Sub where typed_sub(Any, Any);
    subset TakesIntAndString of Sub where typed_sub(Int, Str);

    my TwoArgSub $a;
    my TakesIntAndString $b;

    $a = sub ($a, $b) { ... }; # lives
    $a = sub ($a) { ... }; # dies

    $b = sub (Int $a, Str $b) { ... }; # lives
    $b = sub (Int $a, $b) { ... }; # dies

    # validate subroutines passed to your subroutines (dawg)
    sub doStuff(Int $a, Str $b, &operation where typed_sub(Int, Str)}) {
        ...
    }

    doStuff(99, "bottles of beer", -> Int $a, Str $b { ... }) # lives
    doStuff(99, "bottles of beer", -> Rat $a, Num $b { ... }) # dies

DESCRIPTION

Typed::Subroutines let you specify subroutine types verifying the parameter list so you can have better type checking for first-class functions.

I'll write more docs when I'm less tired.
Something went wrong with that request. Please try again.