select

inline fun <S : DynoSchema, R : Any> Entity<S>.select(body: Selector<S, R>.() -> Unit): R

Executes a selection logic over the schema of this Entity, allowing to define multiple conditional branches based on the actual schema type and providing a fallback via Selector.orElse.

This function is useful when you need to extract a value of type R based on the runtime type of the schema, similar to a when expression but with type-safe branches. Each branch is defined using Selector.on, which is only executed if the schema is of the specified type.

If no Selector.on branch matches and no Selector.orElse is defined, an exception is thrown.

Example:

val result: String = entity.select> {
on<AdminSchema> { ent ->
"Admin: ${ent[name]}"
}
on<UserSchema> { ent ->
"User: ${ent[username]}"
}
orElse { ent ->
"Unknown: ${ent.schema.name()}"
}
}

Throws

IllegalStateException

if no match is found and Selector.orElse is not defined.