associateBy and Lyng:Iterable .toFlow() for kotlin integration simplicity
This commit is contained in:
1 parent
ea2cf1f373
commit
950e8301c3
10 files changed
+86
-12
No files matched your search
@@ -1,4 +1,6 @@
|
||||
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.toList
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import net.sergeych.lyng.*
|
||||
import kotlin.test.*
|
||||
@@ -2311,4 +2313,23 @@ class ScriptTest {
|
||||
assert( ! "5.2".isInteger() )
|
||||
""".trimIndent())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testToFlow() = runTest() {
|
||||
val c = Context()
|
||||
val arr = c.eval("[1,2,3]")
|
||||
// array is iterable so we can:
|
||||
assertEquals(listOf(1,2,3), arr.toFlow(c).map { it.toInt() }.toList())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testAssociateBy() = runTest() {
|
||||
eval("""
|
||||
val m = [123, 456].associateBy { "k:%s"(it) }
|
||||
println(m)
|
||||
assertEquals(123, m["k:123"])
|
||||
assertEquals(456, m["k:456"])
|
||||
""")
|
||||
listOf(1,2,3).associateBy { it * 10 }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user