Posted on

At work, I introduced the use of type wrappers for the many different types of IDs in our system.

value class FooId(val value: UInt) {
    override fun toString() = value.toString()
}

fun UInt.toFooId() = FooId(this)

This allows different types of IDs to have different types in the type system, which makes function signatures more readable. It also helps avoid passing the wrong value into a function by mistake.