Skip to content

Commit

Permalink
add support for mapped lists
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddenton committed Jan 4, 2024
1 parent 2cd0db4 commit 4445ea5
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions data4k/src/main/kotlin/dev/forkhandles/data/DataContainer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ abstract class DataContainer<CONTENT>(

fun <OUT, NEXT> field(mapInFn: (OUT) -> NEXT) = field(mapInFn) { error("no outbound mapping defined") }

// fun <IN, OUT> list(mapInFn: (IN) -> OUT) =
// list(mapInFn) { error("no outbound mapping defined") }
//
fun <IN, OUT> list(mapInFn: (IN) -> OUT) =
list(mapInFn) { error("no outbound mapping defined") }

@JvmName("listDataContainer")
fun <OUT : DataContainer<CONTENT>?> list(mapInFn: (CONTENT) -> OUT) =
list(mapInFn) { it?.data }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class JacksonDataContainerTest : DataContainerContract<JacksonDataContainerTest.
override var listField by list<String>()
override var listIntsField by list<Int>()
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class MapDataContainerTest : DataContainerContract<MapDataContainerTest.SubMap>(
override var listValueField by list(MyType)
override var listSubClassField by list(::SubMap)
override var listIntsField by list<Int>()
override val listMapped by list(Int::toString)

override var objectField by obj(::SubMap)

Expand Down

0 comments on commit 4445ea5

Please sign in to comment.