Skip to content

Commit 3468cb5

Browse files
committed
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.
1 parent 8defe82 commit 3468cb5

4 files changed

Lines changed: 48 additions & 15 deletions

File tree

Package.resolved

Lines changed: 1 addition & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ let package = Package(
1414
targets: ["JSONAPITestLib"])
1515
],
1616
dependencies: [
17-
// antitypical/Result without the Foundation requirement:
18-
.package(url: "https://github.com/mattpolzin/Result", .branch("master"))
1917
],
2018
targets: [
2119
.target(
2220
name: "JSONAPI",
23-
dependencies: ["Result"]),
21+
dependencies: []),
2422
.target(
2523
name: "JSONAPITestLib",
2624
dependencies: ["JSONAPI"]),

Sources/JSONAPI/Resource/Poly.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// Created by Mathew Polzin on 11/22/18.
66
//
77

8-
import Result
9-
108
/// Poly is a protocol to which types that
119
/// are polymorphic belong to. Specifically,
1210
/// Poly1, Poly2, Poly3, etc. types conform
@@ -28,7 +26,7 @@ private func decode<Entity: JSONAPI.EntityType>(_ type: Entity.Type, from contai
2826
} catch (let err) {
2927
ret = .failure(DecodingError.typeMismatch(Entity.Description.self,
3028
.init(codingPath: container.codingPath,
31-
debugDescription: err.localizedDescription,
29+
debugDescription: String(describing: err),
3230
underlyingError: err)))
3331
}
3432
return ret

Sources/JSONAPI/Result.swift

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// Result.swift
3+
// JSONAPI
4+
//
5+
// Created by Mathew Polzin on 12/5/18.
6+
//
7+
8+
enum Result<T, E: Swift.Error> {
9+
case success(T)
10+
case failure(E)
11+
12+
var value: T? {
13+
guard case .success(let val) = self else {
14+
return nil
15+
}
16+
return val
17+
}
18+
19+
var error: E? {
20+
guard case .failure(let err) = self else {
21+
return nil
22+
}
23+
return err
24+
}
25+
26+
func map<U>(_ transform: (T) -> U) -> Result<U, E> {
27+
switch self {
28+
case .failure(let err):
29+
return .failure(err)
30+
case .success(let val):
31+
return .success(transform(val))
32+
}
33+
}
34+
}
35+
36+
extension Result: CustomStringConvertible where T: CustomStringConvertible, E: CustomStringConvertible {
37+
var description: String {
38+
switch self {
39+
case .success(let val):
40+
return String(describing: val)
41+
case .failure(let err):
42+
return String(describing: err)
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)