use lib ".";
use Monads;
multi div(Int $a, 0 --> Maybe[Int]) { Nothing Int }
multi div(Int $a, Int $b --> Maybe[Int]) { Just $a div $b }
sub incr(Int $a) { $a + 1 }
say (&incr =>> &div).(4, 2)
role Maybe {
has $.value;
method gist(::?CLASS:D:) {
return "Nothing" without $!value;
"Just({ $!value.gist })"
}
method bind { $!value }
}
role Maybe[::Type] is Maybe {
has $.type = Type.WHAT;
}
sub Just($val) is export { Maybe[$val].new: :value($val) }
sub Nothing($val) is export { Maybe[$val].new }
multi infix:«=>>»(&a, &b) is export { -> *@val { a(b(|@val).bind) } }