Skip to content

Commit

Permalink
chore: Simplify filter logic for VssNode.findSignal()
Browse files Browse the repository at this point in the history
  • Loading branch information
Chrylo committed Mar 14, 2024
1 parent 4975b33 commit 3579307
Showing 1 changed file with 2 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -223,19 +223,17 @@ fun VssNode.findHeritageLine(
/**
* Finds the given [signal] inside the current [VssNode].
*/
inline fun <reified T : VssSignal<V>, V : Any> VssNode.findSignal(signal: T): T {
inline fun <reified T : VssSignal<V>, V : Any> VssNode.findSignal(signal: T): VssNode {
return heritage
.filterIsInstance<T>()
.first { it.uuid == signal.uuid }
}

/**
* Finds all [VssSignal] which matches the given [KClass.simpleName]. This is useful when multiple nested objects
* with the same Name exists but are pretty much the same besides the [VssNode.vssPath] etc.
*/
inline fun <reified T : VssSignal<V>, V : Any> VssNode.findSignal(type: KClass<T>): Map<String, T> {
inline fun <reified T : VssSignal<V>, V : Any> VssNode.findSignal(type: KClass<T>): Map<String, VssNode> {
return heritage
.filterIsInstance<T>()
.filter { it::class.simpleName == type.simpleName }
.associateBy { it.vssPath }
}

0 comments on commit 3579307

Please sign in to comment.