From 4445ea596cb9f533fc52f3c2c75cbe15028ebd55 Mon Sep 17 00:00:00 2001 From: David Denton Date: Thu, 4 Jan 2024 17:20:33 +0000 Subject: [PATCH] add support for mapped lists --- .../src/main/kotlin/dev/forkhandles/data/DataContainer.kt | 6 +++--- .../kotlin/dev/forkhandles/lens/JacksonDataContainerTest.kt | 1 + .../kotlin/dev/forkhandles/lens/MapDataContainerTest.kt | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/data4k/src/main/kotlin/dev/forkhandles/data/DataContainer.kt b/data4k/src/main/kotlin/dev/forkhandles/data/DataContainer.kt index aea126d..e0567c1 100644 --- a/data4k/src/main/kotlin/dev/forkhandles/data/DataContainer.kt +++ b/data4k/src/main/kotlin/dev/forkhandles/data/DataContainer.kt @@ -38,10 +38,10 @@ abstract class DataContainer( fun field(mapInFn: (OUT) -> NEXT) = field(mapInFn) { error("no outbound mapping defined") } -// fun list(mapInFn: (IN) -> OUT) = -// list(mapInFn) { error("no outbound mapping defined") } -// + fun list(mapInFn: (IN) -> OUT) = + list(mapInFn) { error("no outbound mapping defined") } + @JvmName("listDataContainer") fun ?> list(mapInFn: (CONTENT) -> OUT) = list(mapInFn) { it?.data } diff --git a/data4k/src/test/kotlin/dev/forkhandles/lens/JacksonDataContainerTest.kt b/data4k/src/test/kotlin/dev/forkhandles/lens/JacksonDataContainerTest.kt index 9685386..b05d344 100644 --- a/data4k/src/test/kotlin/dev/forkhandles/lens/JacksonDataContainerTest.kt +++ b/data4k/src/test/kotlin/dev/forkhandles/lens/JacksonDataContainerTest.kt @@ -23,6 +23,7 @@ class JacksonDataContainerTest : DataContainerContract() override var listIntsField by list() override var listValueField by list(MyType) + override val listMapped by list(Int::toString) override var objectField by obj(::SubNodeBacked) override var valueField by field(MyType) override var mappedField by field(String::toInt) diff --git a/data4k/src/test/kotlin/dev/forkhandles/lens/MapDataContainerTest.kt b/data4k/src/test/kotlin/dev/forkhandles/lens/MapDataContainerTest.kt index a4be3a6..c544891 100644 --- a/data4k/src/test/kotlin/dev/forkhandles/lens/MapDataContainerTest.kt +++ b/data4k/src/test/kotlin/dev/forkhandles/lens/MapDataContainerTest.kt @@ -23,6 +23,7 @@ class MapDataContainerTest : DataContainerContract( override var listValueField by list(MyType) override var listSubClassField by list(::SubMap) override var listIntsField by list() + override val listMapped by list(Int::toString) override var objectField by obj(::SubMap)