From 5f14777e0107d6d89085e09641e2016bff22f38d Mon Sep 17 00:00:00 2001 From: Slipp Douglas Thompson Date: Fri, 6 Mar 2020 09:32:53 -0600 Subject: [PATCH] Fix: Made arbitrary-return version use inout too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Swift's type inference gets really confused otherwise, erroring with “Ambiguous use of 'with(_:operations:)`”.  Not sure why, but as before, having the args _exactly_ the same between all the overloads solves it. --- Sources/With.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sources/With.swift b/Sources/With.swift index 1f9c956..2bb6d59 100644 --- a/Sources/With.swift +++ b/Sources/With.swift @@ -24,10 +24,11 @@ public func with(_ subject:SubjectT, operations:(inout Subje /// “With” on an reference-type (object) subject, returning an aribitrary return value from the closure (the subject is still mutated). @inlinable -public func with(_ subject:SubjectT, operations:(SubjectT) throws -> ReturnT) +public func with(_ subject:SubjectT, operations:(inout SubjectT) throws -> ReturnT) rethrows -> ReturnT { - return try operations(subject) + var subject = subject + return try operations(&subject) }