Foggy day
Kotlin - lambda expression -4 : curried function 본문
class KotlinPlayGroundActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_kotlin_play_ground)
val a = "A"
val b = "B"
val c = "C"
val d = "D"
println("func : ${func(a, b, c, d)}")
println("curriedFunc : ${curriedFunc<String, String, String, String>()(b)(c)(d)(a)}")
println("curriedString : ${curriedString(a)(b)(c)(d)}")
}
fun <A, B, C, D> func(a: A, b: B, c: C, d: D): String = "$a, $b, $c, $d"
fun <A, B, C, D> curriedFunc() =
{ a: A ->
{ b: B ->
{ c: C ->
{ d: D ->
"$a, $b, $c, $d"
}
}
}
}
val curriedString: curriedString = { a ->
{ b ->
{ c ->
{ d ->
"$a, $b, $c, $d"
}
}
}
}
}
typealias curriedString = (String) -> (String) -> (String) -> (String) -> String
'Kotlin' 카테고리의 다른 글
Kotlin - recursive function -1 (0) | 2021.03.21 |
---|---|
Kotlin - lambda expression -5 : using data class, value type (0) | 2021.03.21 |
Kotlin - lambda expression -2 : function composition (0) | 2021.03.20 |
Kotlin - lambda expression -1 (0) | 2021.03.20 |
Kotlin - trimMargin, multiple line string (0) | 2021.03.19 |