Package Proposal: ExperimentNumber.jl - annotating an integer with a label to allow dispatch on label

I’m currently making a small module to scratch an itch but wondered if it would be of wider use and worth going the extra step of publishing it.
My primary use case is to be able to pass the run number of a given experiment type to a function call, but define multiple methods for that function based on the experiment type. So we could call a function, say getResults(runNo) but we can define methods like

getResults(runNo::ExperimentNumber{:mine}) = doMyThing(Integer(runNo))
getResults(runNo::ExperimentNumber{:yours}) = doYourThing(Integer(runNo))

I’ve not made a public package before so I thought this might be a simple place to start, but given how lightweight the current definition is, does it even justify being a package, and/or is there a built-in julia feature or published package that already does this?

FYI, The essence of the package is the type definition:

struct ExperimentNumber{E} <: Integer
    i::Integer
    @inline ExperimentNumber(E::Symbol, i::Integer) = new{E}(i)
end

That’s pretty much it! The rest is just some overloading of Base methods for type conversion etc. as far as may be useful or necessary.

Comments, suggestions, feedback welcome!

1 Like