Cannot use mutating member on immutable value: function call returns immutable value: why cannot call mutating func directly on return value?

Hence the existence of functions like :

func with<T>(_ initial: T, update: (inout T) throws -> ()) rethrows -> T {
    var value = initial
    try update(&value)
    return value
}
2 Likes