I ended up using Lazy<String> to solve my pr...
# language-proposals
w
I ended up using Lazy<String> to solve my problem, but I think @diesieben07 is asking for something else 🤔
b
For the record, Swift handles this with
@autoclosure
, another feature I'd like in Kotlin. It allows you to define a closure argument that takes nothing and returns a type. Then, the caller provides anything that resolves to that type and the compiler converts it into a closure. From the caller's perspective, it's just the value, but in reality it's a lazily-evaluated closure. For example:
Copy code
// Swift
func log(trace message: @autoclosure () -> String) {
    if logLevel <= .trace {
        logImmediately(level: .trace, message: message())
    }
}


log(trace: "My \(interpolated) string")
2