mattcurtis
(Matt Curtis)
1
TLDR: result builders' buildExpression
supports @autoclosure
:
@MainActor
@resultBuilder
struct BodyBuilder {
static var shouldExecuteExpressions = false
static func buildExpression<T>(_ expression: @autoclosure () -> T) {
if Self.shouldExecuteExpressions {
_ = expression()
}
}
static func buildBlock(_: Void...) { }
}
This is handy for some code that I'm writing, but it isn't explicitly documented anywhere (though the fact that it works makes sense to me.)
Is it reliable to depend on this, and if so, is it worth documenting?
1 Like
Pippin
(Ethan Pippin)
2
The closest I can find of "documented" is in the Future Directions
that references usage of a valid @autoclosure
to justify other developments.
1 Like
mattcurtis
(Matt Curtis)
3
Yeah I saw that too
The "future" part is why I was surprised it worked