diff --git a/data4k/src/main/kotlin/dev/forkhandles/data/DataContainer.kt b/data4k/src/main/kotlin/dev/forkhandles/data/DataContainer.kt index 5e32cee..8ec17fe 100644 --- a/data4k/src/main/kotlin/dev/forkhandles/data/DataContainer.kt +++ b/data4k/src/main/kotlin/dev/forkhandles/data/DataContainer.kt @@ -22,7 +22,7 @@ abstract class DataContainer( (get(it) as OUT)?.let(mapFn) } - fun > field(factory: ValueFactory) = field(factory::of) + fun , OUT2 : OUT?> field(factory: ValueFactory) = field(factory::of) fun list(mapFn: (IN) -> OUT) = DataProperty, List>(exists) { get(it)?.let { (it as List).map(mapFn) } } @@ -31,7 +31,7 @@ abstract class DataContainer( fun list() = list { it } - fun > obj(mapFn: (CONTENT) -> OUT) = + fun ?> obj(mapFn: (CONTENT) -> OUT) = DataProperty, OUT>(exists) { (get(it) as CONTENT)?.let(mapFn) } fun obj() = DataProperty, CONTENT>(exists) { get(it) as CONTENT? } diff --git a/data4k/src/test/kotlin/dev/forkhandles/lens/DataContainerContract.kt b/data4k/src/test/kotlin/dev/forkhandles/lens/DataContainerContract.kt index ad6959f..c62fa52 100644 --- a/data4k/src/test/kotlin/dev/forkhandles/lens/DataContainerContract.kt +++ b/data4k/src/test/kotlin/dev/forkhandles/lens/DataContainerContract.kt @@ -75,6 +75,7 @@ abstract class DataContainerContract { expectThat(input.decimalField).isEqualTo(1.1234) expectThat(input.mappedField).isEqualTo(123) + expectThrows { container(mapOf("mappedField" to 123)).mappedField } expectThat(input.valueField).isEqualTo(MyType.of(123)) expectThat(input.optionalField).isEqualTo("optional") diff --git a/data4k/src/test/kotlin/dev/forkhandles/lens/MapDataContainerTest.kt b/data4k/src/test/kotlin/dev/forkhandles/lens/MapDataContainerTest.kt index fee2421..6548404 100644 --- a/data4k/src/test/kotlin/dev/forkhandles/lens/MapDataContainerTest.kt +++ b/data4k/src/test/kotlin/dev/forkhandles/lens/MapDataContainerTest.kt @@ -30,7 +30,7 @@ class MapDataContainerTest : DataContainerContract() { override val optionalField by field() override val optionalListField: List? by list() - override val optionalObjectField: SubClassFields? by obj(::SubMap) + override val optionalObjectField: SubMap? by obj(::SubMap) override val optionalValueField: MyType? by field(MyType) }