diff --git a/Argo.xcodeproj/project.pbxproj b/Argo.xcodeproj/project.pbxproj index 26f4b86..e517d3e 100644 --- a/Argo.xcodeproj/project.pbxproj +++ b/Argo.xcodeproj/project.pbxproj @@ -15,7 +15,6 @@ 809754DA1BADF36D00C409E6 /* Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = F87EB6A01ABC5F1300E3B0AB /* Decodable.swift */; }; 809754DB1BADF36D00C409E6 /* StandardTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = F87EB6A11ABC5F1300E3B0AB /* StandardTypes.swift */; }; 809754DC1BADF36D00C409E6 /* DecodeError.swift in Sources */ = {isa = PBXBuildFile; fileRef = F84318A71B9A2D7A00165216 /* DecodeError.swift */; }; - 809754DE1BADF36D00C409E6 /* DecodeOperators.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD9FAF519D0F7900031E006 /* DecodeOperators.swift */; }; 809754DF1BADF36D00C409E6 /* (null) in Sources */ = {isa = PBXBuildFile; }; 809754E21BADF36D00C409E6 /* decode.swift in Sources */ = {isa = PBXBuildFile; fileRef = F87EB69A1ABC5F1300E3B0AB /* decode.swift */; }; 809754E31BADF36D00C409E6 /* flatReduce.swift in Sources */ = {isa = PBXBuildFile; fileRef = F87EB69B1ABC5F1300E3B0AB /* flatReduce.swift */; }; @@ -63,7 +62,6 @@ D0592EBF1B77DD8E00EFEF39 /* JSON.swift in Sources */ = {isa = PBXBuildFile; fileRef = F87EB69F1ABC5F1300E3B0AB /* JSON.swift */; }; D0592EC01B77DD8E00EFEF39 /* Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = F87EB6A01ABC5F1300E3B0AB /* Decodable.swift */; }; D0592EC11B77DD8E00EFEF39 /* StandardTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = F87EB6A11ABC5F1300E3B0AB /* StandardTypes.swift */; }; - D0592EC31B77DD9300EFEF39 /* DecodeOperators.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD9FAF519D0F7900031E006 /* DecodeOperators.swift */; }; D0592EC51B77DD9A00EFEF39 /* decode.swift in Sources */ = {isa = PBXBuildFile; fileRef = F87EB69A1ABC5F1300E3B0AB /* decode.swift */; }; D0592EC61B77DD9A00EFEF39 /* flatReduce.swift in Sources */ = {isa = PBXBuildFile; fileRef = F87EB69B1ABC5F1300E3B0AB /* flatReduce.swift */; }; D0592EC71B77DD9A00EFEF39 /* sequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = F87EB69C1ABC5F1300E3B0AB /* sequence.swift */; }; @@ -83,9 +81,6 @@ EA04D5A11BBF2021001DE23B /* FailureCoalescing.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA04D5A01BBF2021001DE23B /* FailureCoalescing.swift */; }; EA04D5A21BBF2021001DE23B /* FailureCoalescing.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA04D5A01BBF2021001DE23B /* FailureCoalescing.swift */; }; EA04D5A31BBF2021001DE23B /* FailureCoalescing.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA04D5A01BBF2021001DE23B /* FailureCoalescing.swift */; }; - EA04D5A51BBF2047001DE23B /* Argo.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA04D5A41BBF2047001DE23B /* Argo.swift */; }; - EA04D5A61BBF2047001DE23B /* Argo.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA04D5A41BBF2047001DE23B /* Argo.swift */; }; - EA04D5A71BBF2047001DE23B /* Argo.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA04D5A41BBF2047001DE23B /* Argo.swift */; }; EA08313119D5EEAF003B90D7 /* TypeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA08313019D5EEAF003B90D7 /* TypeTests.swift */; }; EA08313319D5EEF2003B90D7 /* post_comments.json in Resources */ = {isa = PBXBuildFile; fileRef = EA08313219D5EEF2003B90D7 /* post_comments.json */; }; EA08313519D5EFC0003B90D7 /* types.json in Resources */ = {isa = PBXBuildFile; fileRef = EA08313419D5EFC0003B90D7 /* types.json */; }; @@ -120,7 +115,6 @@ EA6DD69D1AB383FB00CA3A5B /* PerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA6DD69B1AB383FB00CA3A5B /* PerformanceTests.swift */; }; EA6DD69F1AB384C700CA3A5B /* big_data.json in Resources */ = {isa = PBXBuildFile; fileRef = EA6DD69E1AB384C700CA3A5B /* big_data.json */; }; EA6DD6A01AB384C700CA3A5B /* big_data.json in Resources */ = {isa = PBXBuildFile; fileRef = EA6DD69E1AB384C700CA3A5B /* big_data.json */; }; - EA9159F61BDE74BC00D85292 /* Argo.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA04D5A41BBF2047001DE23B /* Argo.swift */; }; EA9159F71BDE74C700D85292 /* catDecoded.swift in Sources */ = {isa = PBXBuildFile; fileRef = F8EF432E1BBC728A001886BA /* catDecoded.swift */; }; EA9159F81BDE74E400D85292 /* Monad.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA04D5901BBF1F40001DE23B /* Monad.swift */; }; EA9159F91BDE74EB00D85292 /* Functor.swift in Sources */ = {isa = PBXBuildFile; fileRef = EA04D5941BBF1F80001DE23B /* Functor.swift */; }; @@ -135,7 +129,6 @@ EABDF6921A9CD4EA00B6CC83 /* types.plist in Resources */ = {isa = PBXBuildFile; fileRef = EABDF68E1A9CD4EA00B6CC83 /* types.plist */; }; EABDF6941A9CD4FC00B6CC83 /* PListDecodingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EABDF6931A9CD4FC00B6CC83 /* PListDecodingTests.swift */; }; EABDF6951A9CD4FC00B6CC83 /* PListDecodingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = EABDF6931A9CD4FC00B6CC83 /* PListDecodingTests.swift */; }; - EAD9FAF619D0F7900031E006 /* DecodeOperators.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD9FAF519D0F7900031E006 /* DecodeOperators.swift */; }; EAD9FAFE19D2113C0031E006 /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD9FAFD19D2113C0031E006 /* User.swift */; }; EAD9FB0019D211630031E006 /* Comment.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD9FAFF19D211630031E006 /* Comment.swift */; }; EAD9FB0219D211C10031E006 /* Post.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD9FB0119D211C10031E006 /* Post.swift */; }; @@ -185,7 +178,6 @@ F893355F1A4CE83000B88685 /* Argo.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F89335541A4CE83000B88685 /* Argo.framework */; }; F893356E1A4CE8FC00B88685 /* Argo.h in Headers */ = {isa = PBXBuildFile; fileRef = F893356D1A4CE8FC00B88685 /* Argo.h */; settings = {ATTRIBUTES = (Public, ); }; }; F893356F1A4CE8FC00B88685 /* Argo.h in Headers */ = {isa = PBXBuildFile; fileRef = F893356D1A4CE8FC00B88685 /* Argo.h */; settings = {ATTRIBUTES = (Public, ); }; }; - F89335761A4CE93600B88685 /* DecodeOperators.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAD9FAF519D0F7900031E006 /* DecodeOperators.swift */; }; F8ABEBD11D42C67100B4363C /* Runes.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8ABEBD01D42C67100B4363C /* Runes.framework */; }; F8ABEBD31D42C67800B4363C /* Runes.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8ABEBD21D42C67800B4363C /* Runes.framework */; }; F8ABEBD51D42C67E00B4363C /* Runes.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8ABEBD41D42C67E00B4363C /* Runes.framework */; }; @@ -293,7 +285,6 @@ EA04D5981BBF1FA4001DE23B /* Applicative.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Applicative.swift; sourceTree = ""; }; EA04D59C1BBF1FB9001DE23B /* Alternative.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Alternative.swift; sourceTree = ""; }; EA04D5A01BBF2021001DE23B /* FailureCoalescing.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FailureCoalescing.swift; sourceTree = ""; }; - EA04D5A41BBF2047001DE23B /* Argo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Argo.swift; sourceTree = ""; }; EA08313019D5EEAF003B90D7 /* TypeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TypeTests.swift; sourceTree = ""; }; EA08313219D5EEF2003B90D7 /* post_comments.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = post_comments.json; sourceTree = ""; }; EA08313419D5EFC0003B90D7 /* types.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = types.json; sourceTree = ""; }; @@ -317,7 +308,6 @@ EAD9FACF19D0EAB50031E006 /* Argo.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Argo.framework; sourceTree = BUILT_PRODUCTS_DIR; }; EAD9FAD319D0EAB50031E006 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; EAD9FADA19D0EAB60031E006 /* ArgoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ArgoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - EAD9FAF519D0F7900031E006 /* DecodeOperators.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DecodeOperators.swift; sourceTree = ""; }; EAD9FAFD19D2113C0031E006 /* User.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = ""; }; EAD9FAFF19D211630031E006 /* Comment.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Comment.swift; sourceTree = ""; }; EAD9FB0119D211C10031E006 /* Post.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Post.swift; sourceTree = ""; }; @@ -477,7 +467,6 @@ isa = PBXGroup; children = ( F87EB69D1ABC5F1300E3B0AB /* Types */, - EAD9FAE919D0F6480031E006 /* Operators */, F87EB6981ABC5F1300E3B0AB /* Functions */, F8CBE6651A6451F800316FBC /* Extensions */, ); @@ -506,15 +495,6 @@ path = Resources; sourceTree = ""; }; - EAD9FAE919D0F6480031E006 /* Operators */ = { - isa = PBXGroup; - children = ( - EA04D5A41BBF2047001DE23B /* Argo.swift */, - EAD9FAF519D0F7900031E006 /* DecodeOperators.swift */, - ); - path = Operators; - sourceTree = ""; - }; EAD9FAFC19D2110D0031E006 /* Models */ = { isa = PBXGroup; children = ( @@ -992,7 +972,6 @@ 809754DB1BADF36D00C409E6 /* StandardTypes.swift in Sources */, EA9159F91BDE74EB00D85292 /* Functor.swift in Sources */, 809754DA1BADF36D00C409E6 /* Decodable.swift in Sources */, - 809754DE1BADF36D00C409E6 /* DecodeOperators.swift in Sources */, 809754D81BADF36D00C409E6 /* Decoded.swift in Sources */, 809754E41BADF36D00C409E6 /* sequence.swift in Sources */, 809754E21BADF36D00C409E6 /* decode.swift in Sources */, @@ -1002,7 +981,6 @@ 809754E61BADF36D00C409E6 /* RawRepresentable.swift in Sources */, 809754D91BADF36D00C409E6 /* JSON.swift in Sources */, F8C2561C1C3C855C00B70968 /* NSNumber.swift in Sources */, - EA9159F61BDE74BC00D85292 /* Argo.swift in Sources */, EA9159FB1BDE74F800D85292 /* Alternative.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1049,12 +1027,10 @@ F84318AA1B9A2D7A00165216 /* DecodeError.swift in Sources */, D0592EBF1B77DD8E00EFEF39 /* JSON.swift in Sources */, F8EF43311BBC729F001886BA /* catDecoded.swift in Sources */, - D0592EC31B77DD9300EFEF39 /* DecodeOperators.swift in Sources */, EA1200CE1BAB621C006DDBD8 /* RawRepresentable.swift in Sources */, EA04D5931BBF1F40001DE23B /* Monad.swift in Sources */, EA04D5971BBF1F80001DE23B /* Functor.swift in Sources */, D0592EC71B77DD9A00EFEF39 /* sequence.swift in Sources */, - EA04D5A71BBF2047001DE23B /* Argo.swift in Sources */, D0592EC61B77DD9A00EFEF39 /* flatReduce.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1076,11 +1052,9 @@ F87EB6A81ABC5F1300E3B0AB /* sequence.swift in Sources */, F84318A81B9A2D7A00165216 /* DecodeError.swift in Sources */, F8CBE6671A64521000316FBC /* Dictionary.swift in Sources */, - EAD9FAF619D0F7900031E006 /* DecodeOperators.swift in Sources */, F87EB6B01ABC5F1300E3B0AB /* StandardTypes.swift in Sources */, EA04D5911BBF1F40001DE23B /* Monad.swift in Sources */, EA04D5951BBF1F80001DE23B /* Functor.swift in Sources */, - EA04D5A51BBF2047001DE23B /* Argo.swift in Sources */, F8EF432F1BBC728A001886BA /* catDecoded.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -1128,12 +1102,10 @@ F84318A91B9A2D7A00165216 /* DecodeError.swift in Sources */, F8CBE6681A64526300316FBC /* Dictionary.swift in Sources */, F8EF43301BBC729F001886BA /* catDecoded.swift in Sources */, - F89335761A4CE93600B88685 /* DecodeOperators.swift in Sources */, EA1200CD1BAB621C006DDBD8 /* RawRepresentable.swift in Sources */, EA04D5921BBF1F40001DE23B /* Monad.swift in Sources */, EA04D5961BBF1F80001DE23B /* Functor.swift in Sources */, F87EB6B11ABC5F1300E3B0AB /* StandardTypes.swift in Sources */, - EA04D5A61BBF2047001DE23B /* Argo.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Sources/Argo/Functions/decode.swift b/Sources/Argo/Functions/decode.swift index 14e82f6..1822f90 100644 --- a/Sources/Argo/Functions/decode.swift +++ b/Sources/Argo/Functions/decode.swift @@ -79,7 +79,7 @@ public func decode(_ object: Any) -> T? where T == T.DecodedType { - returns: A `Decoded` value where `T` is `Decodable` */ public func decode(_ dict: [String: Any], rootKey: String) -> Decoded where T == T.DecodedType { - return JSON(dict as Any) <| rootKey + return JSON(dict as Any)[rootKey] } /** diff --git a/Sources/Argo/Operators/Argo.swift b/Sources/Argo/Operators/Argo.swift deleted file mode 100644 index 7dfb51f..0000000 --- a/Sources/Argo/Operators/Argo.swift +++ /dev/null @@ -1,10 +0,0 @@ -import Runes - -precedencegroup ArgoDecodePrecedence { - associativity: left - higherThan: RunesApplicativeSequencePrecedence - lowerThan: NilCoalescingPrecedence -} - -infix operator <| : ArgoDecodePrecedence -infix operator <|? : ArgoDecodePrecedence diff --git a/Sources/Argo/Operators/DecodeOperators.swift b/Sources/Argo/Operators/DecodeOperators.swift deleted file mode 100644 index 0e470c0..0000000 --- a/Sources/Argo/Operators/DecodeOperators.swift +++ /dev/null @@ -1,78 +0,0 @@ -import Runes - -/** - Attempt to decode a value at the specified key into the requested type. - - This operator is used to decode a mandatory value from the `JSON`. If the - decoding fails for any reason, this will result in a `.Failure` being - returned. - - - parameter json: The `JSON` object containing the key - - parameter key: The key for the object to decode - - - returns: A `Decoded` value representing the success or failure of the - decode operation -*/ -public func <| (json: JSON, key: String) -> Decoded where A == A.DecodedType { - return json <| [key] -} - -/** - Attempt to decode an optional value at the specified key into the requested - type. - - This operator is used to decode an optional value from the `JSON`. If the key - isn't present in the `JSON`, this will still return `.Success`. However, if - the key exists but the object assigned to that key is unable to be decoded - into the requested type, this will return `.Failure`. - - - parameter json: The `JSON` object containing the key - - parameter key: The key for the object to decode - - - returns: A `Decoded` optional value representing the success or failure of - the decode operation -*/ -public func <|? (json: JSON, key: String) -> Decoded where A == A.DecodedType { - return json <|? [key] -} - -/** - Attempt to decode a value at the specified key path into the requested type. - - This operator is used to decode a mandatory value from the `JSON`. If the - decoding fails for any reason, this will result in a `.Failure` being - returned. - - - parameter json: The `JSON` object containing the key - - parameter keys: The key path for the object to decode, represented by an - array of strings - - - returns: A `Decoded` value representing the success or failure of the - decode operation -*/ -public func <| (json: JSON, keys: [String]) -> Decoded where A == A.DecodedType { - return flatReduce(keys, initial: json, combine: decodedJSON) >>- A.decode -} - -/** - Attempt to decode an optional value at the specified key path into the - requested type. - - This operator is used to decode an optional value from the `JSON`. If any of - the keys in the key path aren't present in the `JSON`, this will still return - `.Success`. However, if the key path exists but the object assigned to the - final key is unable to be decoded into the requested type, this will return - `.Failure`. - - - parameter json: The `JSON` object containing the key - - parameter keys: The key path for the object to decode, represented by an - array of strings - - returns: A `Decoded` optional value representing the success or failure of - the decode operation -*/ -public func <|? (json: JSON, keys: [String]) -> Decoded where A == A.DecodedType { - switch flatReduce(keys, initial: json, combine: decodedJSON) { - case .failure: return .success(.none) - case .success(let x): return A.decode(x) >>- { .success(.some($0)) } - } -} diff --git a/Sources/Argo/Types/JSON.swift b/Sources/Argo/Types/JSON.swift index 726b4cf..e7087ba 100644 --- a/Sources/Argo/Types/JSON.swift +++ b/Sources/Argo/Types/JSON.swift @@ -44,6 +44,53 @@ public extension JSON { } } +extension JSON { + /** + Attempt to extract a value at the specified key path and transform it into + the requested type. + + This method is used to decode a mandatory value from the `JSON`. If the + decoding fails for any reason, this will result in a `.Failure` being + returned. + + - parameter keyPath: The key path for the object to decode, represented by + a variadic list of strings. + + - returns: A `Decoded` value representing the success or failure of the + decode operation + */ + public subscript(keyPath: String...) -> Decoded where T == T.DecodedType { + return flatReduce(keyPath, initial: self, combine: decodedJSON) + .flatMap(T.decode) + } + + /** + Attempt to extract an optional value at the specified key path and + transform it into the requested type. + + This method is used to decode an optional value from the `JSON`. If any of + the keys in the key path aren't present in the `JSON`, this will still return + `.success`. However, if the key path exists but the object assigned to the + final key is unable to be decoded into the requested type, this will return + `.failure`. + + - parameter keyPath: The key path for the object to decode, represented by + a variadic list of strings. + - returns: A `Decoded` optional value representing the success or failure + of the decode operation + */ + public subscript(optional keyPath: String...) -> Decoded where T == T.DecodedType { + switch flatReduce(keyPath, initial: self, combine: decodedJSON) { + case .failure: + return .success(.none) + + case let .success(x): + return T.decode(x) + .flatMap { .success(.some($0)) } + } + } +} + extension JSON: Decodable { /** Decode `JSON` into `Decoded`. diff --git a/Tests/ArgoTests/Models/Booleans.swift b/Tests/ArgoTests/Models/Booleans.swift index 644b642..75648ee 100644 --- a/Tests/ArgoTests/Models/Booleans.swift +++ b/Tests/ArgoTests/Models/Booleans.swift @@ -8,7 +8,7 @@ struct Booleans: Argo.Decodable { static func decode(_ json: JSON) -> Decoded { return curry(Booleans.init) - <^> json <| "realBool" - <*> json <| "numberBool" + <^> json["realBool"] + <*> json["numberBool"] } } diff --git a/Tests/ArgoTests/Models/Comment.swift b/Tests/ArgoTests/Models/Comment.swift index 2736a69..454d2af 100644 --- a/Tests/ArgoTests/Models/Comment.swift +++ b/Tests/ArgoTests/Models/Comment.swift @@ -11,8 +11,8 @@ struct Comment { extension Comment: Argo.Decodable { static func decode(_ json: JSON) -> Decoded { return curry(self.init) - <^> json <| "id" - <*> json <| "text" - <*> json <| ["author", "name"] + <^> json["id"] + <*> json["text"] + <*> json["author", "name"] } } diff --git a/Tests/ArgoTests/Models/Post.swift b/Tests/ArgoTests/Models/Post.swift index aacaa97..a3277d5 100644 --- a/Tests/ArgoTests/Models/Post.swift +++ b/Tests/ArgoTests/Models/Post.swift @@ -12,10 +12,10 @@ struct Post { extension Post: Argo.Decodable { static func decode(_ json: JSON) -> Decoded { return curry(self.init) - <^> json <| "id" - <*> json <| "text" - <*> json <| "author" - <*> json <| "comments" + <^> json["id"] + <*> json["text"] + <*> json["author"] + <*> json["comments"] } } @@ -30,11 +30,11 @@ struct LocationPost { extension LocationPost: Argo.Decodable { static func decode(_ json: JSON) -> Decoded { return curry(self.init) - <^> json <| "id" - <*> json <| "text" - <*> json <| "author" - <*> json <| "comments" - <*> json <|? "location" + <^> json["id"] + <*> json["text"] + <*> json["author"] + <*> json["comments"] + <*> json[optional: "location"] } } @@ -47,8 +47,8 @@ struct Location { extension Location: Argo.Decodable { static func decode(_ json: JSON) -> Decoded { return curry(self.init) - <^> json <| "lat" - <*> json <| "lng" - <*> json <| "title" + <^> json["lat"] + <*> json["lng"] + <*> json["title"] } } diff --git a/Tests/ArgoTests/Models/TestModel.swift b/Tests/ArgoTests/Models/TestModel.swift index 43da4dc..2bfee0b 100644 --- a/Tests/ArgoTests/Models/TestModel.swift +++ b/Tests/ArgoTests/Models/TestModel.swift @@ -18,15 +18,15 @@ extension TestModel: Argo.Decodable { static func decode(_ json: JSON) -> Decoded { let curriedInit = curry(self.init) return curriedInit - <^> json <| "numerics" - <*> json <| ["user_opt", "name"] - <*> json <| "bool" - <*> json <| "string_array" - <*> json <|? "string_array_opt" - <*> json <| ["embedded", "string_array"] - <*> json <|? ["embedded", "string_array_opt"] - <*> json <|? "user_opt" - <*> json <| "dict" + <^> json["numerics"] + <*> json["user_opt", "name"] + <*> json["bool"] + <*> json["string_array"] + <*> json[optional: "string_array_opt"] + <*> json["embedded", "string_array"] + <*> json[optional: "embedded", "string_array_opt"] + <*> json[optional: "user_opt"] + <*> json["dict"] } } @@ -45,16 +45,16 @@ struct TestModelNumerics { extension TestModelNumerics: Argo.Decodable { static func decode(_ json: JSON) -> Decoded { let f = curry(self.init) - <^> json <| "int" - <*> json <| "int64" - <*> json <| "int64_string" - <*> json <| "double" - <*> json <| "float" - <*> json <|? "int_opt" + <^> json["int"] + <*> json["int64"] + <*> json["int64_string"] + <*> json["double"] + <*> json["float"] + <*> json[optional: "int_opt"] return f - <*> json <| "uint" - <*> json <| "uint64" - <*> json <| "uint64_string" + <*> json["uint"] + <*> json["uint64"] + <*> json["uint64_string"] } } diff --git a/Tests/ArgoTests/Models/User.swift b/Tests/ArgoTests/Models/User.swift index 58bd964..6b5af79 100644 --- a/Tests/ArgoTests/Models/User.swift +++ b/Tests/ArgoTests/Models/User.swift @@ -11,8 +11,8 @@ struct User { extension User: Argo.Decodable { static func decode(_ json: JSON) -> Decoded { return curry(self.init) - <^> json <| "id" - <*> (json <| ["userinfo", "name"] <|> json <| "name") - <*> json <|? "email" + <^> json["id"] + <*> (json["userinfo", "name"] <|> json["name"]) + <*> json[optional: "email"] } } diff --git a/Tests/ArgoTests/Tests/RawRepresentableTests.swift b/Tests/ArgoTests/Tests/RawRepresentableTests.swift index 43f76a2..11392a7 100644 --- a/Tests/ArgoTests/Tests/RawRepresentableTests.swift +++ b/Tests/ArgoTests/Tests/RawRepresentableTests.swift @@ -21,8 +21,8 @@ class RawRepresentable: XCTestCase { "another": JSON.string("NotCoolStringBro") ]) - let string: TestRawString? = (json <| "string").value - let another: TestRawString? = (json <| "another").value + let string: TestRawString? = json["string"].value + let another: TestRawString? = json["another"].value XCTAssertEqual(TestRawString.CoolString, string) XCTAssertEqual(TestRawString.NotCoolStringBro, another) } @@ -33,8 +33,8 @@ class RawRepresentable: XCTestCase { "one": JSON.number(1) ]) - let zero: TestRawInt? = (json <| "zero").value - let one: TestRawInt? = (json <| "one").value + let zero: TestRawInt? = json["zero"].value + let one: TestRawInt? = json["one"].value XCTAssertEqual(TestRawInt.zero, zero) XCTAssertEqual(TestRawInt.one, one) } diff --git a/Tests/ArgoTests/Tests/TypeTests.swift b/Tests/ArgoTests/Tests/TypeTests.swift index 3b0d98a..b51a16c 100644 --- a/Tests/ArgoTests/Tests/TypeTests.swift +++ b/Tests/ArgoTests/Tests/TypeTests.swift @@ -39,7 +39,7 @@ class TypeTests: XCTestCase { func testBooleanIdentification() { let j = json(fromFile: "booleans").map(JSON.init)! - let boolean: JSON? = (j <| "realBool").value + let boolean: JSON? = j["realBool"].value XCTAssertEqual(boolean, .bool(true)) }