Skip to content

Commit

Permalink
Improved typing
Browse files Browse the repository at this point in the history
  • Loading branch information
stefankoppier committed Jun 26, 2024
1 parent 204be3b commit ad745a3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mappie-api/src/commonMain/kotlin/tech/mappie/api/Mappie.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

package tech.mappie.api

public abstract class Mappie<FROM, TO> {
public abstract class Mappie<in FROM, out TO> {

/**
* Map [from] to an instance of [TO].
Expand Down
17 changes: 17 additions & 0 deletions testing/src/main/kotlin/testing/ListToNullableListMapper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package testing

import tech.mappie.api.ObjectMappie

data class SourceList(val value: List<String>)

data class TargetList(val value: List<String>?)

object NullableListFromListMapper : ObjectMappie<SourceList, TargetList>() {
override fun map(from: SourceList): TargetList = mapping {
TargetList::value fromProperty SourceList::value via StringIdentityMapper.forList
}
}

object StringIdentityMapper : ObjectMappie<String, String>() {
override fun map(from: String): String = from
}
15 changes: 15 additions & 0 deletions testing/src/test/kotlin/testing/ListToNullableListMapperTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package testing

import org.junit.jupiter.api.Test
import kotlin.test.assertEquals

class ListToNullableListMapperTest {

@Test
fun `map List to nullable List via NullableListFromList`() {
assertEquals(
TargetList(listOf("A", "B")),
NullableListFromListMapper.map(SourceList(listOf("A", "B"))),
)
}
}

0 comments on commit ad745a3

Please sign in to comment.