From 457c34a66170b1b5d395bff24297958902a81de7 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Wed, 7 Mar 2018 19:02:54 +0100 Subject: Add index as mapping function parameter. --- src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/main/kotlin/pl/treksoft/kvision/data') diff --git a/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt b/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt index b8d13c77..80a05ba7 100644 --- a/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt +++ b/src/main/kotlin/pl/treksoft/kvision/data/DataContainer.kt @@ -45,7 +45,7 @@ class DataContainer( private val model: ObservableList, private val factory: (Int, M) -> C, private val filter: ((Int, M) -> Boolean)? = null, - private val mapping: ((List) -> List)? = null, + private val mapping: ((List>) -> List>)? = null, private val container: Container = VPanel(), init: (DataContainer.() -> Unit)? = null ) : @@ -106,12 +106,12 @@ class DataContainer( } singleRender { container.removeAll() - val mapped = mapping?.invoke(model) ?: model - val indexed = mapped.mapIndexed { index, m -> index to m } + val indexed = model.mapIndexed { index, m -> index to m } + val mapped = mapping?.invoke(indexed) ?: indexed val children = if (filter != null) { - indexed.filter { p -> filter.invoke(p.first, p.second) } + mapped.filter { p -> filter.invoke(p.first, p.second) } } else { - indexed + mapped }.map { p -> factory(p.first, p.second) } container.addAll(children) } @@ -147,7 +147,7 @@ class DataContainer( model: ObservableList, factory: (Int, M) -> C, filter: ((Int, M) -> Boolean)? = null, - mapping: ((List) -> List)? = null, + mapping: ((List>) -> List>)? = null, container: Container = VPanel(), init: (DataContainer.() -> Unit)? = null ): DataContainer { -- cgit