Joakim
01/05/2023, 1:57 PM.let
, but for an arbitrary number of variables and types.
"X".let { x ->
"Y".let { y ->
"Z".let { z ->
println(x + y + z) // XYZ
}
}
}
In Clojure, the let
-form lets us do it like this
(let [x "X"
y "Y"
z "Z"]
(println (str x y z))) ;; "XYZ"
How would you do this in Kotlin? Could perhaps invoke .let
on a hashmap with values of type Any
, but at that point i’d probably just extract it to a function insteadkenkyee
01/05/2023, 2:00 PMJacob
01/05/2023, 2:02 PMrun {
val x = "x"
val y = "Y"
val z = "Z"
println(x + y + z) // XYZ
}
Joakim
01/05/2023, 2:03 PMJBordage
01/05/2023, 8:44 PMval (x, y, z) = Triple("X", "Y", "Z")
println(x + y + z) // "XYZ"
println("$x$y$z") // "XYZ", but using string interpolation
nkiesel
01/06/2023, 3:23 AMrun {
val (x, y, z) = listOf("X", "Y", "Z")
println(x + y + z) // XYZ
}