mirror of
https://github.com/encounter/JSONAPI.git
synced 2026-03-30 11:18:38 -07:00
Remove Result dependency in favor of a super stripped down internally scoped Result enum. This won't interfere with other Result libraries and I was not exposing the Result anyway.
This commit is contained in:
+1
-9
@@ -1,15 +1,7 @@
|
||||
{
|
||||
"object": {
|
||||
"pins": [
|
||||
{
|
||||
"package": "Result",
|
||||
"repositoryURL": "https://github.com/mattpolzin/Result",
|
||||
"state": {
|
||||
"branch": "master",
|
||||
"revision": "b98e238da6ea030fa7862ae6fd6500552370019c",
|
||||
"version": null
|
||||
}
|
||||
}
|
||||
|
||||
]
|
||||
},
|
||||
"version": 1
|
||||
|
||||
+1
-3
@@ -14,13 +14,11 @@ let package = Package(
|
||||
targets: ["JSONAPITestLib"])
|
||||
],
|
||||
dependencies: [
|
||||
// antitypical/Result without the Foundation requirement:
|
||||
.package(url: "https://github.com/mattpolzin/Result", .branch("master"))
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
name: "JSONAPI",
|
||||
dependencies: ["Result"]),
|
||||
dependencies: []),
|
||||
.target(
|
||||
name: "JSONAPITestLib",
|
||||
dependencies: ["JSONAPI"]),
|
||||
|
||||
@@ -5,8 +5,6 @@
|
||||
// Created by Mathew Polzin on 11/22/18.
|
||||
//
|
||||
|
||||
import Result
|
||||
|
||||
/// Poly is a protocol to which types that
|
||||
/// are polymorphic belong to. Specifically,
|
||||
/// Poly1, Poly2, Poly3, etc. types conform
|
||||
@@ -28,7 +26,7 @@ private func decode<Entity: JSONAPI.EntityType>(_ type: Entity.Type, from contai
|
||||
} catch (let err) {
|
||||
ret = .failure(DecodingError.typeMismatch(Entity.Description.self,
|
||||
.init(codingPath: container.codingPath,
|
||||
debugDescription: err.localizedDescription,
|
||||
debugDescription: String(describing: err),
|
||||
underlyingError: err)))
|
||||
}
|
||||
return ret
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// Result.swift
|
||||
// JSONAPI
|
||||
//
|
||||
// Created by Mathew Polzin on 12/5/18.
|
||||
//
|
||||
|
||||
enum Result<T, E: Swift.Error> {
|
||||
case success(T)
|
||||
case failure(E)
|
||||
|
||||
var value: T? {
|
||||
guard case .success(let val) = self else {
|
||||
return nil
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
var error: E? {
|
||||
guard case .failure(let err) = self else {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func map<U>(_ transform: (T) -> U) -> Result<U, E> {
|
||||
switch self {
|
||||
case .failure(let err):
|
||||
return .failure(err)
|
||||
case .success(let val):
|
||||
return .success(transform(val))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Result: CustomStringConvertible where T: CustomStringConvertible, E: CustomStringConvertible {
|
||||
var description: String {
|
||||
switch self {
|
||||
case .success(let val):
|
||||
return String(describing: val)
|
||||
case .failure(let err):
|
||||
return String(describing: err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user