Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tadzik/typed-subroutines
Better type checking for first-class functions
https://github.com/tadzik/typed-subroutines
Last synced: 8 days ago
JSON representation
Better type checking for first-class functions
- Host: GitHub
- URL: https://github.com/tadzik/typed-subroutines
- Owner: tadzik
- Created: 2012-07-01T19:40:04.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2017-05-12T11:04:55.000Z (over 7 years ago)
- Last Synced: 2024-10-11T20:56:29.358Z (about 1 month ago)
- Language: Perl6
- Size: 7.81 KB
- Stars: 3
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README
Awesome Lists containing this project
README
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 { ... }) # diesDESCRIPTION
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.