Skip to content

Commit

Permalink
Move files around to make more sense
Browse files Browse the repository at this point in the history
  • Loading branch information
gfontenot committed Mar 27, 2015
1 parent 95784cc commit d99eaa3
Show file tree
Hide file tree
Showing 12 changed files with 124 additions and 123 deletions.
154 changes: 77 additions & 77 deletions Argo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
46 changes: 0 additions & 46 deletions Argo/Operators/JSONOperators.swift

This file was deleted.

47 changes: 47 additions & 0 deletions Argo/Operators/Operators.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,51 @@
import Runes

infix operator <| { associativity left precedence 150 }
infix operator <|? { associativity left precedence 150 }
infix operator <|| { associativity left precedence 150 }
infix operator <||? { associativity left precedence 150 }

// MARK: Values

// Pull value from JSON
public func <|<A where A: JSONDecodable, A == A.DecodedType>(json: JSON, key: String) -> Decoded<A> {
return decodeObject(json) >>- { (A.decode <^> $0[key]) ?? .MissingKey(key) }
}

// Pull optional value from JSON
public func <|?<A where A: JSONDecodable, A == A.DecodedType>(json: JSON, key: String) -> Decoded<A?> {
return .optional(json <| key)
}

// Pull embedded value from JSON
public func <|<A where A: JSONDecodable, A == A.DecodedType>(json: JSON, keys: [String]) -> Decoded<A> {
return flatReduce(keys, json, <|) >>- A.decode
}

// Pull embedded optional value from JSON
public func <|?<A where A: JSONDecodable, A == A.DecodedType>(json: JSON, keys: [String]) -> Decoded<A?> {
return .optional(json <| keys)
}

// MARK: Arrays

// Pull array from JSON
public func <||<A where A: JSONDecodable, A == A.DecodedType>(json: JSON, key: String) -> Decoded<[A]> {
return json <| key >>- decodeArray
}

// Pull optional array from JSON
public func <||?<A where A: JSONDecodable, A == A.DecodedType>(json: JSON, key: String) -> Decoded<[A]?> {
return .optional(json <|| key)
}

// Pull embedded array from JSON
public func <||<A where A: JSONDecodable, A == A.DecodedType>(json: JSON, keys: [String]) -> Decoded<[A]> {
return json <| keys >>- decodeArray
}

// Pull embedded optional array from JSON
public func <||?<A where A: JSONDecodable, A == A.DecodedType>(json: JSON, keys: [String]) -> Decoded<[A]?> {
return .optional(json <|| keys)
}

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit d99eaa3

Please sign in to comment.