Oh, you’re right, my code doesn’t compile due to the duplicate generic parameter name T. Sorry about that. And yes, what you wrote is pretty much where I intended to end up. Weirdly enough, it doesn’t compile, though, and all I get is a nondescript “Command SwiftCompile failed with a nonzero exit code” 😕 In my actual code where I stumbled across this, it does compile, though. I tried but I couldn’t manage to get my sample code (or yours) to compile…
FWIW, here’s my actual code:
/// Adds a side effect that is performed whenever any of the tweaks’ value changes.
@discardableResult
public static func addSideEffect<each Value>(to tweak: repeat Tweak<each Value>, sideEffect: @escaping () -> Void) -> (repeat Tweak<each Value>.SideEffectID) {
func add<V>(to tweak: Tweak<V>) -> CustomSideEffect.ID {
let sideEffect = CustomSideEffect(action: sideEffect)
tweak.tweaks.store.sideEffectPerformer.add(.custom(sideEffect), for: tweak.id)
return sideEffect.id
}
return (repeat add(to: each tweak))
}