Skip to content

Commit

Permalink
minor formatting updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanhimmelman committed Feb 24, 2017
1 parent f893bc0 commit b24305e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
20 changes: 8 additions & 12 deletions Sources/ImmutableMappable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public extension Map {

/// Returns a `[String: BaseMappable]` or throws an error.
public func value<T: BaseMappable>(_ key: String, nested: Bool? = nil, delimiter: String = ".", file: StaticString = #file, function: StaticString = #function, line: UInt = #line) throws -> [String: T] {

let currentValue = self.currentValue(for: key, nested: nested, delimiter: delimiter)
guard let jsonDictionary = currentValue as? [String: Any] else {
throw MapError(key: key, currentValue: currentValue, reason: "Cannot cast to '[String: Any]'", file: file, function: function, line: line)
Expand All @@ -139,6 +140,7 @@ public extension Map {

/// Returns a `[String: BaseMappable]` using transform or throws an error.
public func value<Transform: TransformType>(_ key: String, nested: Bool? = nil, delimiter: String = ".", using transform: Transform, file: StaticString = #file, function: StaticString = #function, line: UInt = #line) throws -> [String: Transform.Object] {

let currentValue = self.currentValue(for: key, nested: nested, delimiter: delimiter)
guard let jsonDictionary = currentValue as? [String: Any] else {
throw MapError(key: key, currentValue: currentValue, reason: "Cannot cast to '[String: Any]'", file: file, function: function, line: line)
Expand All @@ -155,13 +157,11 @@ public extension Map {

// MARK: [[BaseMappable]]
/// Returns a `[[BaseMappable]]` or throws an error.
public func value<T: BaseMappable>(_ key: String, nested: Bool? = nil, delimiter: String = ".",
file: StaticString = #file, function: StaticString = #function,
line: UInt = #line) throws -> [[T]] {
public func value<T: BaseMappable>(_ key: String, nested: Bool? = nil, delimiter: String = ".", file: StaticString = #file, function: StaticString = #function, line: UInt = #line) throws -> [[T]] {

let currentValue = self.currentValue(for: key, nested: nested, delimiter: delimiter)
guard let json2DArray = currentValue as? [[Any]] else {
throw MapError(key: key, currentValue: currentValue, reason: "Cannot cast to '[[Any]]'", file: file,
function: function, line: line)
throw MapError(key: key, currentValue: currentValue, reason: "Cannot cast to '[[Any]]'", file: file, function: function, line: line)
}
return try json2DArray.map { jsonArray in
try jsonArray.map { jsonObject -> T in
Expand All @@ -171,10 +171,8 @@ public extension Map {
}

/// Returns a `[[BaseMappable]]` using transform or throws an error.
public func value<Transform: TransformType>(_ key: String, nested: Bool? = nil, delimiter: String = ".",
using transform: Transform, file: StaticString = #file,
function: StaticString = #function,
line: UInt = #line) throws -> [[Transform.Object]] {
public func value<Transform: TransformType>(_ key: String, nested: Bool? = nil, delimiter: String = ".", using transform: Transform, file: StaticString = #file, function: StaticString = #function, line: UInt = #line) throws -> [[Transform.Object]] {

let currentValue = self.currentValue(for: key, nested: nested, delimiter: delimiter)
guard let json2DArray = currentValue as? [[Any]] else {
throw MapError(key: key, currentValue: currentValue, reason: "Cannot cast to '[[Any]]'",
Expand All @@ -183,9 +181,7 @@ public extension Map {
return try json2DArray.enumerated().map { i, jsonArray in
try jsonArray.enumerated().map { j, json -> Transform.Object in
guard let object = transform.transformFromJSON(json) else {
throw MapError(key: "\(key)[\(i)][\(j)]", currentValue: json,
reason: "Cannot transform to '\(Transform.Object.self)' using \(transform)", file: file,
function: function, line: line)
throw MapError(key: "\(key)[\(i)][\(j)]", currentValue: json, reason: "Cannot transform to '\(Transform.Object.self)' using \(transform)", file: file, function: function, line: line)
}
return object
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/TransformOperators.swift
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ public func >>> <Transform: TransformType>(left: [[Transform.Object]], right: (M
}
}

/// Optional array of objects with transform
/// Optional array of array of objects with transform
public func <- <Transform: TransformType>(left: inout [[Transform.Object]]?, right: (Map, Transform)) {
let (map, transform) = right
switch map.mappingType {
Expand Down Expand Up @@ -502,7 +502,7 @@ public func >>> <Transform: TransformType>(left: [[Transform.Object]]?, right: (
}


/// Implicitly unwrapped Optional array of objects with transform
/// Implicitly unwrapped Optional array of array of objects with transform
public func <- <Transform: TransformType>(left: inout [[Transform.Object]]!, right: (Map, Transform)) {
let (map, transform) = right
switch map.mappingType {
Expand Down

0 comments on commit b24305e

Please sign in to comment.