Skip to content

Commit ad3e308

Browse files
committed
0.8.1
1 parent 5925907 commit ad3e308

5 files changed

Lines changed: 17 additions & 111 deletions

File tree

Babel.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = 'Babel'
3-
s.version = '0.8.0'
3+
s.version = '0.8.1'
44
s.summary = 'JSON! *Pure Swift*, failure driven, inferred *but unambiguous*, with powerful *but optional* operators.'
55

66
s.license = { :type => 'MIT', :file => 'LICENSE' }

Sources/Decodable.swift

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,29 +79,31 @@ public extension Value {
7979
return try T.decode(self)
8080
}
8181

82-
func decode<T: Decodable>(type: T.Type = T.self, ignoreFailure: Bool = false) throws -> T? {
83-
do {
84-
return try T.decode(self)
85-
} catch let error {
86-
if ignoreFailure { return nil }
87-
else { throw error }
88-
}
89-
}
90-
9182
func decode<T: Decodable>(type: T.Type = T.self, ignoreFailures: Bool = false) throws -> [T] {
9283
return try asArray().decode(ignoreFailures: ignoreFailures)
9384
}
9485

9586
func decode<K: Decodable, V: Decodable>(
96-
keyType: K.Type = K.self,
97-
valueType: V.Type = V.self,
87+
keyType: K.Type = K.self, valueType: V.Type = V.self,
9888
ignoreFailures: Bool = false
9989
) throws -> [K: V] {
10090

10191
return try asDictionary().decode(ignoreFailures: ignoreFailures)
10292
}
10393
}
10494

95+
extension Array: Decodable where Element: Decodable {
96+
public static func _decode(_ value: Value) throws -> Array {
97+
return try value.asArray().decode()
98+
}
99+
}
100+
101+
extension Dictionary: Decodable where Key: Decodable, Value: Decodable {
102+
public static func _decode(_ value: Babel.Value) throws -> Dictionary {
103+
return try value.asDictionary().decode()
104+
}
105+
}
106+
105107
extension Bool: Decodable {
106108
public static func _decode(_ value: Value) throws -> Bool { return try value.asBool() }
107109
}

Sources/Operators.swift

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ public func =><T: Decodable>(lhs: Value, rhs: Int) throws -> T {
1212
return try (lhs => rhs).decode()
1313
}
1414

15-
public func =><T: Decodable>(lhs: Value, rhs: Int) throws -> [T] {
16-
return try (lhs => rhs).decode()
17-
}
18-
19-
public func =><K: Decodable, V: Decodable>(lhs: Value, rhs: Int) throws -> [K: V] {
20-
return try (lhs => rhs).decode()
21-
}
22-
2315
// MARK: Nil Chaining
2416

2517
public func =>(lhs: Value?, rhs: Int) throws -> Value? {
@@ -30,14 +22,6 @@ public func =><T: Decodable>(lhs: Value?, rhs: Int) throws -> T? {
3022
return try (lhs => rhs)?.decode()
3123
}
3224

33-
public func =><T: Decodable>(lhs: Value?, rhs: Int) throws -> [T]? {
34-
return try (lhs => rhs)?.decode()
35-
}
36-
37-
public func =><K: Decodable, V: Decodable>(lhs: Value?, rhs: Int) throws -> [K: V]? {
38-
return try (lhs => rhs)?.decode()
39-
}
40-
4125
// MARK: - Array (Accept Null) -
4226

4327
public func =>?(lhs: Value, rhs: Int) throws -> Value? {
@@ -48,14 +32,6 @@ public func =>?<T: Decodable>(lhs: Value, rhs: Int) throws -> T? {
4832
return try (lhs =>? rhs)?.decode()
4933
}
5034

51-
public func =>?<T: Decodable>(lhs: Value, rhs: Int) throws -> [T]? {
52-
return try (lhs =>? rhs)?.decode()
53-
}
54-
55-
public func =>?<K: Decodable, V: Decodable>(lhs: Value, rhs: Int) throws -> [K: V]? {
56-
return try (lhs =>? rhs)?.decode()
57-
}
58-
5935
// MARK: Nil Chaining
6036

6137
public func =>?(lhs: Value?, rhs: Int) throws -> Value? {
@@ -66,14 +42,6 @@ public func =>?<T: Decodable>(lhs: Value?, rhs: Int) throws -> T? {
6642
return try (lhs =>? rhs)?.decode()
6743
}
6844

69-
public func =>?<T: Decodable>(lhs: Value?, rhs: Int) throws -> [T]? {
70-
return try (lhs =>? rhs)?.decode()
71-
}
72-
73-
public func =>?<K: Decodable, V: Decodable>(lhs: Value?, rhs: Int) throws -> [K: V]? {
74-
return try (lhs =>? rhs)?.decode()
75-
}
76-
7745
// MARK: - Array (Accept Out of Bounds or Null) -
7846

7947
public func =>??(lhs: Value, rhs: Int) throws -> Value? {
@@ -84,14 +52,6 @@ public func =>??<T: Decodable>(lhs: Value, rhs: Int) throws -> T? {
8452
return try (lhs =>?? rhs)?.decode()
8553
}
8654

87-
public func =>??<T: Decodable>(lhs: Value, rhs: Int) throws -> [T]? {
88-
return try (lhs =>?? rhs)?.decode()
89-
}
90-
91-
public func =>??<K: Decodable, V: Decodable>(lhs: Value, rhs: Int) throws -> [K: V]? {
92-
return try (lhs =>?? rhs)?.decode()
93-
}
94-
9555
// MARK: Nil Chaining
9656

9757
public func =>??(lhs: Value?, rhs: Int) throws -> Value? {
@@ -102,14 +62,6 @@ public func =>??<T: Decodable>(lhs: Value?, rhs: Int) throws -> T? {
10262
return try (lhs =>?? rhs)?.decode()
10363
}
10464

105-
public func =>??<T: Decodable>(lhs: Value?, rhs: Int) throws -> [T]? {
106-
return try (lhs =>?? rhs)?.decode()
107-
}
108-
109-
public func =>??<K: Decodable, V: Decodable>(lhs: Value?, rhs: Int) throws -> [K: V]? {
110-
return try (lhs =>?? rhs)?.decode()
111-
}
112-
11365
// MARK: - Dictionary -
11466

11567
public func =>(lhs: Value, rhs: String) throws -> Value {
@@ -120,14 +72,6 @@ public func =><T: Decodable>(lhs: Value, rhs: String) throws -> T {
12072
return try (lhs => rhs).decode()
12173
}
12274

123-
public func =><T: Decodable>(lhs: Value, rhs: String) throws -> [T] {
124-
return try (lhs => rhs).decode()
125-
}
126-
127-
public func =><K: Decodable, V: Decodable>(lhs: Value, rhs: String) throws -> [K: V] {
128-
return try (lhs => rhs).decode()
129-
}
130-
13175
// MARK: Nil Chaining
13276

13377
public func =>(lhs: Value?, rhs: String) throws -> Value? {
@@ -138,14 +82,6 @@ public func =><T: Decodable>(lhs: Value?, rhs: String) throws -> T? {
13882
return try (lhs => rhs)?.decode()
13983
}
14084

141-
public func =><T: Decodable>(lhs: Value?, rhs: String) throws -> [T]? {
142-
return try (lhs => rhs)?.decode()
143-
}
144-
145-
public func =><K: Decodable, V: Decodable>(lhs: Value?, rhs: String) throws -> [K: V]? {
146-
return try (lhs => rhs)?.decode()
147-
}
148-
14985
// MARK: - Dictionary (Accept Null) -
15086

15187
public func =>?(lhs: Value, rhs: String) throws -> Value? {
@@ -156,14 +92,6 @@ public func =>?<T: Decodable>(lhs: Value, rhs: String) throws -> T? {
15692
return try (lhs =>? rhs)?.decode()
15793
}
15894

159-
public func =>?<T: Decodable>(lhs: Value, rhs: String) throws -> [T]? {
160-
return try (lhs =>? rhs)?.decode()
161-
}
162-
163-
public func =>?<K: Decodable, V: Decodable>(lhs: Value, rhs: String) throws -> [K: V]? {
164-
return try (lhs =>? rhs)?.decode()
165-
}
166-
16795
// MARK: Nil Chaining
16896

16997
public func =>?(lhs: Value?, rhs: String) throws -> Value? {
@@ -174,14 +102,6 @@ public func =>?<T: Decodable>(lhs: Value?, rhs: String) throws -> T? {
174102
return try (lhs =>? rhs)?.decode()
175103
}
176104

177-
public func =>?<T: Decodable>(lhs: Value?, rhs: String) throws -> [T]? {
178-
return try (lhs =>? rhs)?.decode()
179-
}
180-
181-
public func =>?<K: Decodable, V: Decodable>(lhs: Value?, rhs: String) throws -> [K: V]? {
182-
return try (lhs =>? rhs)?.decode()
183-
}
184-
185105
// MARK: - Dictionary (Accept Missing Key or Null) -
186106

187107
public func =>??(lhs: Value, rhs: String) throws -> Value? {
@@ -192,14 +112,6 @@ public func =>??<T: Decodable>(lhs: Value, rhs: String) throws -> T? {
192112
return try (lhs =>?? rhs)?.decode()
193113
}
194114

195-
public func =>??<T: Decodable>(lhs: Value, rhs: String) throws -> [T]? {
196-
return try (lhs =>?? rhs)?.decode()
197-
}
198-
199-
public func =>??<K: Decodable, V: Decodable>(lhs: Value, rhs: String) throws -> [K: V]? {
200-
return try (lhs =>?? rhs)?.decode()
201-
}
202-
203115
// MARK: Nil Chaining
204116

205117
public func =>??(lhs: Value?, rhs: String) throws -> Value? {
@@ -209,11 +121,3 @@ public func =>??(lhs: Value?, rhs: String) throws -> Value? {
209121
public func =>??<T: Decodable>(lhs: Value?, rhs: String) throws -> T? {
210122
return try (lhs =>?? rhs)?.decode()
211123
}
212-
213-
public func =>??<T: Decodable>(lhs: Value?, rhs: String) throws -> [T]? {
214-
return try (lhs =>?? rhs)?.decode()
215-
}
216-
217-
public func =>??<K: Decodable, V: Decodable>(lhs: Value?, rhs: String) throws -> [K: V]? {
218-
return try (lhs =>?? rhs)?.decode()
219-
}

Xcode/Babel.playground/Contents.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public struct YouTubeResponse: Decodable {
117117
case .functionExplicit:
118118
return try YouTubeResponse(
119119
apiVersion: value.asDictionary().valueFor("apiVersion").asDouble(),
120-
data: value.asDictionary().maybeValueFor("data", nilOnNull: true, throwOnMissing: true)?.decode(type: YouTubeData.self, ignoreFailure: false)
120+
data: value.asDictionary().maybeValueFor("data", nilOnNull: true, throwOnMissing: true)?.decode(type: YouTubeData.self)
121121
)
122122

123123
case .unwrappingAndChecking:
@@ -165,7 +165,7 @@ public struct YouTubeData: Decodable {
165165
case .functionExplicit:
166166
return try YouTubeData(
167167
totalItems: value.asDictionary().valueFor("totalItems").asInt(),
168-
firstItem: value.asDictionary().valueFor("items").asArray().maybeValueAt(0, nilOnNull: true, throwOnMissing: false)?.decode(type: YouTubeDataItem.self, ignoreFailure: false),
168+
firstItem: value.asDictionary().valueFor("items").asArray().maybeValueAt(0, nilOnNull: true, throwOnMissing: false)?.decode(type: YouTubeDataItem.self),
169169
items: value.asDictionary().valueFor("items").asArray().decode(type: YouTubeDataItem.self, ignoreFailures: false)
170170
)
171171

Xcode/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>FMWK</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>0.8.0</string>
18+
<string>0.8.1</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

0 commit comments

Comments
 (0)