Conceptually this should also work, subject to availability of Equality of functions. One of the workarounds discussed in that thread was to treat closure literal as a syntax sugar for compiler generated struct in certain contexts. With this workaround in mind, it could look like this:
struct Lazy<Value, Thunk: Function0, let thunk: @autoclosure Thunk> where Thunk.ResultType == Value {
var _value: Value?
var wrappedValue: Value {
get {
if let v = _value { return v }
let v = thunk()
_value = v
}
set {
_value = newValue
}
}
}
func makeInitialValue(arg: Int) -> Bla { ... }
struct Usage {
@Lazy<Bla, _, makeInitialValue(arg: 42)> var prop: Bla
}