Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Extractor] array and arrayOptional are not needed anymore #201

Merged
merged 1 commit into from
May 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions Sources/Extractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,15 @@ public struct Extractor {
}

/// - Throws: DecodeError or an arbitrary ErrorType
@available(*, unavailable, renamed: "value(_:)")
public func array<T: Decodable>(_ keyPath: KeyPath) throws -> [T] {
guard let array: [T] = try arrayOptional(keyPath) else {
throw DecodeError.missingKeyPath(keyPath)
}

return array
fatalError()
}

/// - Throws: DecodeError or an arbitrary ErrorType
@available(*, unavailable, renamed: "valueOptional(_:)")
public func arrayOptional<T: Decodable>(_ keyPath: KeyPath) throws -> [T]? {
return try _rawValue(keyPath).map([T].decode)
fatalError()
}

/// - Throws: DecodeError or an arbitrary ErrorType
Expand Down
4 changes: 2 additions & 2 deletions Sources/Operators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public func <|? <T: Decodable>(e: Extractor, keyPath: KeyPath) throws -> T? {
/// - Throws: DecodeError or an arbitrary ErrorType
@available(*, unavailable, renamed: "<|")
public func <|| <T: Decodable>(e: Extractor, keyPath: KeyPath) throws -> [T] {
return try e.array(keyPath)
fatalError()
}

/// - Throws: DecodeError or an arbitrary ErrorType
@available(*, unavailable, renamed: "<|?")
public func <||? <T: Decodable>(e: Extractor, keyPath: KeyPath) throws -> [T]? {
return try e.arrayOptional(keyPath)
fatalError()
}

/// - Throws: DecodeError or an arbitrary ErrorType
Expand Down
4 changes: 2 additions & 2 deletions Sources/StandardLib.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ extension Array: Decodable where Element: Decodable {

/// - Throws: DecodeError or an arbitrary ErrorType
public static func decode(from data: Data, rootKeyPath: KeyPath) throws -> [Element] {
return try Extractor(from: data).array(rootKeyPath)
return try Extractor(from: data).value(rootKeyPath)
}

/// - Throws: DecodeError or an arbitrary ErrorType
public static func decode(_ JSON: Any, rootKeyPath: KeyPath) throws -> [Element] {
return try Extractor(JSON).array(rootKeyPath)
return try Extractor(JSON).value(rootKeyPath)
}
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/HimotokiTests/TransformerTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ private struct URLsByTransformer: Himotoki.Decodable {
return self.init(
value: try Transformer { try toURL($0) }.apply(e <| "value"),
valueOptional: try URLTransformer.apply(e.valueOptional("valueOptional")),
array: try URLTransformer.apply(e.array("array")),
array: try URLTransformer.apply(e.value("array")),
arrayOptional: try URLTransformer.apply(e <|? "arrayOptional"),
dictionary: try URLTransformer.apply(e <| "dictionary"),
dictionaryOptional: try URLTransformer.apply(e.dictionaryOptional("dictionaryOptional"))
Expand Down