[fleet, rhizomedb] Yet another util function

GitOrigin-RevId: 9a1d34a9a1feb5edb313df4c75432fcdcdbfae81
This commit is contained in:
Valery Teplyakov
2025-05-16 15:02:52 +02:00
committed by intellij-monorepo-bot
parent 4123a5154e
commit 401febfb7f

View File

@@ -148,6 +148,12 @@ fun predicateQuery(p: () -> Boolean): Query<Unit> = queryOf(Unit).filter { p() }
fun <T> Query<T>.filter(p: (T) -> Boolean): Query<T> =
flatMap { t -> if (p(t)) setOf(t) else emptySet() }
/**
* Returns a query containing only matches of the original query that are instances of specified type parameter [R].
* */
inline fun <reified R> Query<*>.filterIsInstance(): Query<R> =
flatMap { t -> if (t is R) setOf(t) else emptySet() }
/**
* version of [filter] working with [Match]
* [p] has to be a *pure* function of a database