DanielZ
01/30/2024, 7:00 PMEnvironment
and lenses
.
When running following test:
@Test
fun `extract a list of domain ids from environment`() {
data class MyDomainId(val value: String)
val DOMAIN_ID by EnvironmentKey.csv(",")
.map(
{ strings: List<String> -> strings.map(::MyDomainId) },
{ next -> next.map(MyDomainId::value) })
.of()
.required()
val domainIds = listOf(MyDomainId("1"), MyDomainId("2"))
val environment = Environment.defaults(DOMAIN_ID of domainIds)
environment[DOMAIN_ID] shouldBe domainIds
}
it ends up in
Missing elements from index 1
expected:<[MyDomainId(value=1), MyDomainId(value=2)]> but was:<[MyDomainId(value=1)]>
Expected :[MyDomainId(value=1), MyDomainId(value=2)]
Actual :[MyDomainId(value=1)]
<Click to see difference>
io.kotest.assertions.AssertionFailedError: Missing elements from index 1
Replacing the delimiter in csv()
to for example ":"
makes the test pass.
My findings so far: it’s not the csv()
part - this happens when I split
the string by hand.
How can I use both type-safety of the lens
and ,
as separator? Where is my misunderstanding?dave
01/30/2024, 7:05 PMEnvironmentKey.value(MyDomainId.multi.required("")
DanielZ
01/30/2024, 7:40 PMval DOMAIN_ID by EnvironmentKey
.map(::MyDomainId, MyDomainId::value)
.multi
.of()
.required()