[tests] Cover KT-63654 with test cases

This commit is contained in:
Stanislav Ruban
2023-11-21 19:39:30 +01:00
committed by Space Team
parent 6471080c48
commit 9956c0f83b
3 changed files with 39 additions and 0 deletions
@@ -0,0 +1,15 @@
// ISSUE: KT-63654
// WITH_STDLIB
data class State<S, out A>(private val action: (S) -> Pair<A, S>) {
fun <B> flatMap(f: (A) -> State<S, B>): State<S, B> =
State { s0: S ->
val (a, s1) = action(s0)
f(a).action(s1)
}
}
fun box(): String {
State<String, Int> { 42 to "" }.flatMap { i -> State { i.toLong() to "" } }
return "OK"
}
@@ -0,0 +1,12 @@
// ISSUE: KT-63654
class Klass<in A>(private val action: (A) -> Unit) {
fun <B> execute(value: B, klassB: Klass<B>) {
klassB.action(value)
}
}
fun box(): String {
Klass { a: Int -> a.inc() }.execute("", Klass { b: String -> b.length })
return "OK"
}
@@ -0,0 +1,12 @@
// ISSUE: KT-63654
class Klass<out A>(private val action: () -> A) {
fun <B> execute(klassB: Klass<B>) {
klassB.action()
}
}
fun box(): String {
Klass { 42 }.execute(Klass { "" })
return "OK"
}