Conversion, promotion, user API?

Here’s a generic approach that should work:

struct FooID
    value::Int32
    q1::Int8
    q2::Int8
    q3::Int8

    function FooID(value)
        d = digits(abs(value), pad=3)
        return new(value, d[1], d[2], d[3])
    end
end

fooid(x::FooID) = x
fooid(x::Integer) = FooID(x)

struct Bar
    fooid::FooID
end

fooid(x::Bar) = x.fooid

hasfuture(x) = fooid(x).q1 > 2

Now you only have to define one version of hasfuture, haswhatever, isvalid, etc. :slight_smile:

1 Like