module typetestdeco
function zip = |a,b, zipper| {
require(a: length() == b: length(), "Arrays must have the same size")
for ( var i = 0, i < a: length(), i = i + 1) {
zipper(a :get(i), b :get(i))
}
}
function checkparams = |checkers...| {
let _deco_ = |fun| {
let _wrapped_ = |args...|{
zip( checkers, args, |f,v| -> require(f(v), v+" is not of required type!") )
return fun: invokeWithArguments(args)
}
return _wrapped_
}
return _deco_
}
# Type checking function factory
function checktype = |t| -> |v| -> v oftype t
@checkparams(checktype(Integer.class), checktype(String.class), checktype(Double.class))
function foo = |a, b, c|{
println(":D")
}
function main = |args| {
foo(42, "foo", 13.37)
foo(13.37, 42, "foo")
}
Last active
August 29, 2015 14:05
-
-
Save artpej/f588c9c58d678bf25ddb to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
:)