Skip to content

Commit 8bc37f9

Browse files
authored
Merge pull request #61 from modelix/filter-loaded-typed
fix: support .filterLoaded() on a child list of typed nodes
2 parents cad033c + 772fd67 commit 8bc37f9

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

metamodel-runtime/src/commonMain/kotlin/org/modelix/metamodel/ChildAccessor.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ abstract class ChildAccessor<ChildT : ITypedNode>(
1111
protected val parent: INode,
1212
protected val role: IChildLink,
1313
protected val childConcept: IConcept,
14-
protected val childType: KClass<ChildT>,
14+
val childType: KClass<ChildT>,
1515
): Iterable<ChildT> {
1616
fun isEmpty(): Boolean = !iterator().hasNext()
1717

1818
fun getSize(): Int {
1919
return this.count()
2020
}
2121

22+
fun untypedNodes() : Iterable<INode> = parent.getChildren(role)
23+
2224
override fun iterator(): Iterator<ChildT> {
23-
return parent.getChildren(role).map {
25+
return untypedNodes().map {
2426
when (childConcept) {
2527
is GeneratedConcept<*, *> -> it.typed(childType)
2628
else -> throw RuntimeException("Unsupported concept type: ${childConcept::class} (${childConcept.getLongName()})")
@@ -44,3 +46,7 @@ abstract class ChildAccessor<ChildT : ITypedNode>(
4446
removeUnwrapped(child.unwrap())
4547
}
4648
}
49+
50+
fun <ChildT : ITypedNode> ChildAccessor<ChildT>.filterLoaded(): List<ChildT> {
51+
return untypedNodes().asSequence().filter { it.isValid }.map { it.typed(childType) }.toList()
52+
}

0 commit comments

Comments
 (0)