bitmask-event-wrapper

Installation
SKILL.md

One value class over an integer flag set

A lower layer — a player, a permission system, a change-notification callback — hands up a single integer whose bits each mean something. Left raw, every call site writes the mask by hand and every call site can get it wrong in a different way. The wrapper is small enough to be obviously correct:

// adapted — the source is a data class with no all-bits predicate; both changes are the point of
// the traps below
@JvmInline
value class EventSet(val flags: Int) {
    fun contains(event: Int): Boolean = flags and event != 0
    fun containsAny(vararg events: Int): Boolean = events.any { flags and it != 0 }
    fun containsAll(mask: Int): Boolean = flags and mask == mask
}
Installs
2
GitHub Stars
35
First Seen
6 days ago
bitmask-event-wrapper — maxrave-dev/kotlin-footguns