import ComposableArchitecture import Foundation @usableFromInline enum SetAction { case operation(f: (inout State, Value) -> Effect) case keyPath(WritableKeyPath, effect: Effect) case optionalKeyPath(WritableKeyPath, effect: Effect) @usableFromInline func callAsFunction(state: inout State, value: Value) -> Effect { switch self { case let .operation(f: f): return f(&state, value) case let .keyPath(keyPath, effect): state[keyPath: keyPath] = value return effect case let .optionalKeyPath(keyPath, effect): state[keyPath: keyPath] = value return effect } } @usableFromInline static func operation(_ f: @escaping (inout State, Value) -> Void) -> Self { .operation(f: { state, value in f(&state, value) return .none }) } }