Is there a clean way to bind multiple variables to a local scope? Similar to
.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 instead