ArgCheck.jl is a very small package that allows to replace
function f(A, B, k, n)
(k > 0) && (n > 0) || throw(ArgumentError("k and n must be positive".))
k > n || throw(ArgumentError("k > n must hold."))
size(A) == size(B) || throw(DimensionMismatch("size(A) == size(B) must hold."))
# doit
end
by
function f(A, B, k, n)
@argcheck k > 0 && n > 0
@argcheck k > n
@argcheck size(A) == size(B) DimensionMismatch
# doit
end
Nice. For reference, there’s been a discussion about including a similar feature in Julia itself, possibly with support for conditions on the returned value too: https://github.com/JuliaLang/julia/pull/15495