The current implementation of TestPair can be initialized with a throwing or non-throwing autoclosure, but the getters for left and right can't know which, so they always have to assume non-throwing and force-try.
Here's some code from @IanKeen that might help:
public enum Throwing { }
public enum NonThrowing { }
public struct TestPair<Left, Right, Mode> {
private let _leftClosure: () throws -> Left
private let _rightClosure: () throws -> Right
}
extension TestPair where Mode == NonThrowing {
public init(leftClosure: @escaping () -> Left, rightClosure: @escaping () -> Right) {
self.init(
_leftClosure: leftClosure,
_rightClosure: rightClosure
)
}
public var left: Left {
get { try! _leftClosure() }
}
public var right: Right {
get { try! _rightClosure() }
}
}
extension TestPair where Mode == Throwing {
init(leftClosure: @escaping () throws -> Left, rightClosure: @escaping () throws -> Right) {
self.init(
_leftClosure: leftClosure,
_rightClosure: rightClosure
)
}
public var left: Left {
get throws { try _leftClosure() }
}
public var right: Right {
get throws { try _rightClosure() }
}
}
Usage:

Further ramblings from me:
might do protocol TestMode {} and then enum Throwing: TestMode so I can constraint TestMode in the definition of TestPair
The current implementation of
TestPaircan be initialized with a throwing or non-throwing autoclosure, but the getters forleftandrightcan't know which, so they always have to assume non-throwing and force-try.Here's some code from @IanKeen that might help:
Usage:

Further ramblings from me: