]) { ... } request(parameters: [ .nickname("hiroshi") ]) "> ]) { ... } request(parameters: [ .nickname("hiroshi") ]) "> ]) { ... } request(parameters: [ .nickname("hiroshi") ]) ">
enum MyRequestTrait: RequestParameterFragmentTrait {}
extension RequestParameterFragment where Trait == MyRequestTrait {
public static func nickname(_ value: String) -> Self {
.init(jsonKey: "nickname", jsonValue: .init(value))
}
}
func request(parameters: [RequestParameterFragment<MyRequestTrait>]) {
...
}
request(parameters: [
.nickname("hiroshi")
])
public protocol RequestParameterFragmentTrait {}
public struct RequestParameterFragment<Trait: RequestParameterFragmentTrait>: Hashable {
public let jsonKey: String
public let jsonValue: JSON
init(jsonKey: String, jsonValue: JSON) {
self.jsonKey = jsonKey
self.jsonValue = jsonValue
}
func applyParameter(to json: inout JSON) {
json[jsonKey] = json
}
}