diff --git a/Sources/fluentinterface/FluentInterface.swift b/Sources/fluentinterface/FluentInterface.swift index 4eccb22..faf4634 100644 --- a/Sources/fluentinterface/FluentInterface.swift +++ b/Sources/fluentinterface/FluentInterface.swift @@ -26,6 +26,9 @@ public postfix func - (lhs: FluentInterface) -> T { /// ``` /// resource https://www.appcoda.com.tw/fluent-interface/ @dynamicMemberLookup public struct FluentInterface { + + public typealias FISetter = ((Value) -> FluentInterface) + let subject: Subject // 因為要動到 subject 的屬性,所以 keyPath 的型別必須是 WritableKeyPath @@ -43,20 +46,20 @@ public postfix func - (lhs: FluentInterface) -> T { /// [Flentinterface] get the subject. public func unwrappingSubject() -> Subject { subject - } - /// [Fluentinterface] Quick way to touch subject and remain fluent interface - /// - Parameter handlel: A cloure to get the subject - public nonmutating func handlingSubject(_ handle: - (Subject) -> Void) -> Self { - handle(subject) - return self - } - /// [Fluentinterface] Quick way to manipulate subject and remain fluent interface - /// - Parameter handle: A cloure to inout set subject - public nonmutating func manipulateSubjct(_ handle: - (inout Subject) -> Void) -> Self { - var subject = self.subject - handle(&subject) - return FluentInterface(subject: subject) - } + } + /// [Fluentinterface] Quick way to touch subject and remain fluent interface + /// - Parameter handlel: A cloure to get the subject + public nonmutating func handlingSubject(_ handle: + (Subject) -> Void) -> Self { + handle(subject) + return self + } + /// [Fluentinterface] Quick way to manipulate subject and remain fluent interface + /// - Parameter handle: A cloure to inout set subject + public nonmutating func manipulateSubjct(_ handle: + (inout Subject) -> Void) -> Self { + var subject = self.subject + handle(&subject) + return FluentInterface(subject: subject) + } }