Code clean and some refactorings in 'getLambdaIfExistsAndMarkInstructions'

This commit is contained in:
Michael Bogdanov
2016-02-08 14:59:49 +03:00
parent c75b514551
commit 0f90dc1649
19 changed files with 143 additions and 154 deletions
@@ -0,0 +1,5 @@
import test.*
fun box(): String {
return ContentTypeByExtension.processRecords { ext -> ext }
}
@@ -0,0 +1,18 @@
package test
object ContentTypeByExtension {
inline fun processRecords(crossinline operation: (String) -> String) =
listOf("O", "K").map {
val ext = B(it)
operation(ext.toLowerCase())
}.joinToString("")
}
inline fun A.toLowerCase(): String = (this as B).value
open class A
open class B(val value: String) : A()
@@ -0,0 +1,5 @@
import test.*
fun box(): String {
return ContentTypeByExtension.processRecords { ext -> ext }
}
@@ -0,0 +1,18 @@
package test
object ContentTypeByExtension {
inline fun processRecords(crossinline operation: (String) -> String) =
{
val ext = B("OK")
operation(ext.toLowerCase())
}()
}
inline fun A.toLowerCase(): String = (this as B).value
open class A
open class B(val value: String) : A()
@@ -0,0 +1,5 @@
import test.*
fun box(): String {
return processRecords { ext -> ext + "K" }
}
@@ -0,0 +1,5 @@
package test
inline fun foo(x: String) = x
inline fun processRecords(block: (String) -> String) = block(foo("O"))
@@ -0,0 +1,5 @@
import test.*
fun box(): String {
return processRecords { "O" + it }
}
@@ -0,0 +1,11 @@
package test
inline fun foo(x: String) = x
class A {
fun test(s: String) = s
}
inline fun processRecords(block: (String) -> String): String {
return A().test(block(foo("K")))
}
@@ -0,0 +1,7 @@
import test.*
fun box(): String {
val result = processRecords { "B" + it }
return if (result == "BOK1") "OK" else "fail: $result"
}
@@ -0,0 +1,11 @@
package test
inline fun foo(x: String, y: String) = x + y
class A {
fun test(s: String) = s
}
inline fun processRecords(block: (String) -> String): String {
return A().test(block(foo("O", foo("K", "1"))))
}
@@ -0,0 +1,5 @@
import test.*
fun box(): String {
return processRecords { a, b -> a + b}
}
@@ -0,0 +1,10 @@
package test
inline fun foo(x: String) = x
fun test(a: String, s: String) = s
inline fun processRecords(block: (String, String) -> String): String {
return test("stub", block(foo("O"), foo("K")))
}
@@ -0,0 +1,5 @@
import test.*
fun box(): String? {
return processRecords("O") { this + "K" }
}
@@ -0,0 +1,5 @@
package test
inline fun foo(x: String) = x
inline fun processRecords(s: String?, block: String.(String) -> String) = s?.block(foo("O"))