Can i check struct validity using external method?

Hey,

I wanted to externalize my validity checks like that :

struct S{PT}
    par::PT
    function S(par)
        rez = new{typeof(par)}(par)
        check(rez) && return rez
    end
end
function check(rez::S{PT}) where PT
    # do my checks...
    return S.par < 2
end

S(1)
S(2)

The reason is that the check function is actually more general than this checker, and without it i have to recopy its code inside the constructor.

Why is julia yelling at me ?

You meant to write the check as

1 Like