Skip to content

tadzik/Typed-Subroutines

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
t
 
 
 
 
 
 
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.

About

Better type checking for first-class functions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Other 100.0%