diff --git a/Package.resolved b/Package.resolved
index bf2a730..fdcbe13 100644
--- a/Package.resolved
+++ b/Package.resolved
@@ -8,6 +8,15 @@
"revision" : "31b5b18556610a5639d50eb56575b6a54db13f1c",
"version" : "1.1.0"
}
+ },
+ {
+ "identity" : "swift-functional",
+ "kind" : "remoteSourceControl",
+ "location" : "git@github.com:spacenation/swift-functional.git",
+ "state" : {
+ "revision" : "45aed19a2399e4100955db9ca7a2ea88009b6332",
+ "version" : "0.1.0"
+ }
}
],
"version" : 2
diff --git a/Package.swift b/Package.swift
index 72c6418..1424aa4 100644
--- a/Package.swift
+++ b/Package.swift
@@ -23,13 +23,15 @@ let package = Package(
targets: ["StringEncoder"])
],
dependencies: [
- .package(url: "git@github.com:spacenation/swift-binary.git", .upToNextMajor(from: "1.1.0"))
+ .package(url: "git@github.com:spacenation/swift-binary.git", .upToNextMajor(from: "1.1.0")),
+ .package(url: "git@github.com:spacenation/swift-functional.git", .upToNextMajor(from: "0.1.0"))
],
targets: [
.target(
name: "Coder",
dependencies: [
- .product(name: "Binary", package: "swift-binary")
+ .product(name: "Binary", package: "swift-binary"),
+ .product(name: "Functional", package: "swift-functional")
]
),
.testTarget(
@@ -42,7 +44,8 @@ let package = Package(
name: "BinaryDecoder",
dependencies: [
"Coder",
- .product(name: "Binary", package: "swift-binary")
+ .product(name: "Binary", package: "swift-binary"),
+ .product(name: "Functional", package: "swift-functional")
]
),
.testTarget(name: "BinaryDecoderTests", dependencies: ["BinaryDecoder"]),
@@ -53,7 +56,8 @@ let package = Package(
name: "BinaryEncoder",
dependencies: [
"Coder",
- .product(name: "Binary", package: "swift-binary")
+ .product(name: "Binary", package: "swift-binary"),
+ .product(name: "Functional", package: "swift-functional")
]
),
.testTarget(
@@ -64,7 +68,8 @@ let package = Package(
.target(
name: "StringDecoder",
dependencies: [
- "Coder"
+ "Coder",
+ .product(name: "Functional", package: "swift-functional")
]
),
.testTarget(
@@ -75,7 +80,8 @@ let package = Package(
.target(
name: "StringEncoder",
dependencies: [
- "Coder"
+ "Coder",
+ .product(name: "Functional", package: "swift-functional")
]
),
.testTarget(
diff --git a/Sources/Coder/Coder.swift b/Sources/Coder/Coder.swift
index b42dce5..525a85c 100644
--- a/Sources/Coder/Coder.swift
+++ b/Sources/Coder/Coder.swift
@@ -1 +1,2 @@
@_exported import Binary
+@_exported import Functional
diff --git a/Sources/Coder/Currying/Curry.swift b/Sources/Coder/Currying/Curry.swift
deleted file mode 100644
index fe279fe..0000000
--- a/Sources/Coder/Currying/Curry.swift
+++ /dev/null
@@ -1,33 +0,0 @@
-import Foundation
-
-public func curry(_ fn: @escaping (A, B) -> C) -> (A) -> (B) -> C {
- { (a: A) -> (B) -> C in { (b: B) -> C in fn(a, b) } }
-}
-
-public func curry(_ fn: @escaping (A, B, C) -> D) -> (A) -> (B) -> (C) -> D {
- { (a: A) -> (B) -> (C) -> D in { (b: B) -> (C) -> D in { (c: C) -> D in fn(a, b, c) } } }
-}
-
-public func curry(_ fn: @escaping (A, B, C, D) -> E) -> (A) -> (B) -> (C) -> (D) -> E {
- { (a: A) -> (B) -> (C) -> (D) -> E in { (b: B) -> (C) -> (D) -> E in { (c: C) -> (D) -> E in { (d: D) -> E in fn(a, b, c, d) } } } }
-}
-
-public func curry(_ fn: @escaping (A, B, C, D, E) -> F) -> (A) -> (B) -> (C) -> (D) -> (E) -> F {
- { (a: A) -> (B) -> (C) -> (D) -> (E) -> F in { (b: B) -> (C) -> (D) -> (E) -> F in { (c: C) -> (D) -> (E) -> F in { (d: D) -> (E) -> F in { (e: E) -> F in fn(a, b, c, d, e) } } } } }
-}
-
-public func curry(_ fn: @escaping (A, B, C, D, E, F) -> G) -> (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> G {
- { (a: A) -> (B) -> (C) -> (D) -> (E) -> (F) -> G in { (b: B) -> (C) -> (D) -> (E) -> (F) -> G in { (c: C) -> (D) -> (E) -> (F) -> G in { (d: D) -> (E) -> (F) -> G in { (e: E) -> (F) -> G in { (f: F) -> G in fn(a, b, c, d, e, f) } } } } } }
-}
-
-public func curry(_ fn: @escaping (A, B, C, D, E, F, G) -> H) -> (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> H {
- { (a: A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> H in { (b: B) -> (C) -> (D) -> (E) -> (F) -> (G) -> H in { (c: C) -> (D) -> (E) -> (F) -> (G) -> H in { (d: D) -> (E) -> (F) -> (G) -> H in { (e: E) -> (F) -> (G) -> H in { (f: F) -> (G) -> H in { (g: G) -> H in fn(a, b, c, d, e, f, g) } } } } } } }
-}
-
-public func curry(_ fn: @escaping (A, B, C, D, E, F, G, H) -> I) -> (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> (H) -> I {
- { (a: A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> (H) -> I in { (b: B) -> (C) -> (D) -> (E) -> (F) -> (G) -> (H) -> I in { (c: C) -> (D) -> (E) -> (F) -> (G) -> (H) -> I in { (d: D) -> (E) -> (F) -> (G) -> (H) -> I in { (e: E) -> (F) -> (G) -> (H) -> I in { (f: F) -> (G) -> (H) -> I in { (g: G) -> (H) -> I in { (h: H) -> I in fn(a, b, c, d, e, f, g, h) } } } } } } } }
-}
-
-public func curry(_ fn: @escaping (A, B, C, D, E, F, G, H, I) -> J) -> (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> (H) -> (I) -> J {
- { (a: A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> (H) -> (I) -> J in { (b: B) -> (C) -> (D) -> (E) -> (F) -> (G) -> (H) -> (I) -> J in { (c: C) -> (D) -> (E) -> (F) -> (G) -> (H) -> (I) -> J in { (d: D) -> (E) -> (F) -> (G) -> (H) -> (I) -> J in { (e: E) -> (F) -> (G) -> (H) -> (I) -> J in { (f: F) -> (G) -> (H) -> (I) -> J in { (g: G) -> (H) -> (I) -> J in { (h: H) -> (I) -> J in { (i: I) -> J in fn(a, b, c, d, e, f, g, h, i) } } } } } } } } }
-}
diff --git a/Sources/Coder/Currying/Uncurry.swift b/Sources/Coder/Currying/Uncurry.swift
deleted file mode 100644
index 2c04611..0000000
--- a/Sources/Coder/Currying/Uncurry.swift
+++ /dev/null
@@ -1,37 +0,0 @@
-import Foundation
-
-public func uncurry(_ fn: @escaping (A) -> (B) -> C) -> (A, B) -> C {
- { (a: A, b: B) -> C in fn(a)(b) }
-}
-
-public func uncurry(_ fn: @escaping (A) -> (B) -> (C) -> D) -> (A, B, C) -> D {
- { (a: A, b: B, c: C) -> D in fn(a)(b)(c) }
-}
-
-public func uncurry(_ fn: @escaping (A) -> (B) -> (C) -> (D) -> E) -> (A, B, C, D) -> E {
- { (a: A, b: B, c: C, d: D) -> E in fn(a)(b)(c)(d) }
-}
-
-public func uncurry(_ fn: @escaping (A) -> (B) -> (C) -> (D) -> (E) -> F) -> (A, B, C, D, E) -> F {
- { (a: A, b: B, c: C, d: D, e: E) -> F in fn(a)(b)(c)(d)(e) }
-}
-
-public func uncurry(_ fn: @escaping (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> G) -> (A, B, C, D, E, F) -> G {
- { (a: A, b: B, c: C, d: D, e: E, f: F) -> G in fn(a)(b)(c)(d)(e)(f) }
-}
-
-public func uncurry(_ fn: @escaping (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> H) -> (A, B, C, D, E, F, G) -> H {
- { (a: A, b: B, c: C, d: D, e: E, f: F, g: G) -> H in fn(a)(b)(c)(d)(e)(f)(g) }
-}
-
-public func uncurry(_ fn: @escaping (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> (H) -> I) -> (A, B, C, D, E, F, G, H) -> I {
- { (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H) -> I in fn(a)(b)(c)(d)(e)(f)(g)(h) }
-}
-
-public func uncurry(_ fn: @escaping (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> (H) -> (I) -> J) -> (A, B, C, D, E, F, G, H, I) -> J {
- { (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i: I) -> J in fn(a)(b)(c)(d)(e)(f)(g)(h)(i) }
-}
-
-public func uncurry(_ fn: @escaping (A) -> (B) -> (C) -> (D) -> (E) -> (F) -> (G) -> (H) -> (I) -> (J) -> K) -> (A, B, C, D, E, F, G, H, I, J) -> K {
- { (a: A, b: B, c: C, d: D, e: E, f: F, g: G, h: H, i: I, j: J) -> K in fn(a)(b)(c)(d)(e)(f)(g)(h)(i)(j) }
-}
diff --git a/Sources/Coder/Functions/Constant.swift b/Sources/Coder/Functions/Constant.swift
deleted file mode 100644
index 88a2f72..0000000
--- a/Sources/Coder/Functions/Constant.swift
+++ /dev/null
@@ -1,5 +0,0 @@
-import Foundation
-
-public func constant(_ a: A) -> (B) -> A {
- { _ in a }
-}
diff --git a/Sources/Coder/Functions/Flip.swift b/Sources/Coder/Functions/Flip.swift
deleted file mode 100644
index 4347662..0000000
--- a/Sources/Coder/Functions/Flip.swift
+++ /dev/null
@@ -1,9 +0,0 @@
-import Foundation
-
-public func flip(_ f: @escaping (A) -> (B) -> C) -> (B) -> (A) -> C {
- { a in { b in f(b)(a) } }
-}
-
-public func flip(_ f: @escaping (A, B) -> C) -> (B, A) -> C {
- { f($1, $0) }
-}
diff --git a/Sources/Coder/Functions/Identity.swift b/Sources/Coder/Functions/Identity.swift
deleted file mode 100644
index a757b93..0000000
--- a/Sources/Coder/Functions/Identity.swift
+++ /dev/null
@@ -1,5 +0,0 @@
-import Foundation
-
-public func identity(_ a: A) -> A {
- a
-}
diff --git a/Sources/Coder/Functions/Reverse.swift b/Sources/Coder/Functions/Reverse.swift
deleted file mode 100644
index 36767a5..0000000
--- a/Sources/Coder/Functions/Reverse.swift
+++ /dev/null
@@ -1,9 +0,0 @@
-import Foundation
-
-public func reverse(_ f: @escaping (A) -> (B) -> (C) -> D) -> (C) -> (B) -> (A) -> D {
- { a in { b in { c in f(c)(b)(a) } } }
-}
-
-public func reverse(_ f: @escaping (A, B, C) -> D) -> (C, B, A) -> D {
- { f($2, $1, $0) }
-}
diff --git a/Sources/StringDecoder/Predicates/Character+Predicates.swift b/Sources/StringDecoder/Predicates/Character+Predicates.swift
index 36e7c2b..6079275 100644
--- a/Sources/StringDecoder/Predicates/Character+Predicates.swift
+++ b/Sources/StringDecoder/Predicates/Character+Predicates.swift
@@ -12,6 +12,10 @@ public func isDigit(_ c: Character) -> Bool {
"0"..."9" ~= c
}
+public func isPositiveDigit(_ c: Character) -> Bool {
+ "1"..."9" ~= c
+}
+
public func isLetter(_ c: Character) -> Bool {
c.isLetter
}
diff --git a/Tests/CoderTests/CurryingTests/CurryTests.swift b/Tests/CoderTests/CurryingTests/CurryTests.swift
deleted file mode 100644
index aed14e4..0000000
--- a/Tests/CoderTests/CurryingTests/CurryTests.swift
+++ /dev/null
@@ -1,18 +0,0 @@
-import XCTest
-import Coder
-
-final class CurryTests: XCTestCase {
- func testCurry() {
- struct S3: Equatable {
- let a: Int
- let b: Double
- let c: Bool
- }
-
- XCTAssert(curry(+)(1)(2) == 3)
-
- XCTAssert(curry(S3.init)(1)(2.0)(true) == S3(a: 1, b: 2.0, c: true))
- }
-}
-
-
diff --git a/Tests/CoderTests/CurryingTests/UncurryTests.swift b/Tests/CoderTests/CurryingTests/UncurryTests.swift
deleted file mode 100644
index 6c566c3..0000000
--- a/Tests/CoderTests/CurryingTests/UncurryTests.swift
+++ /dev/null
@@ -1,8 +0,0 @@
-import XCTest
-import Coder
-
-final class UncurryTests: XCTestCase {
- func testUncurry() {
- XCTAssert(uncurry(curry(*))(2,2) == 4)
- }
-}
diff --git a/Tests/CoderTests/FunctionsTests/FlipTests.swift b/Tests/CoderTests/FunctionsTests/FlipTests.swift
deleted file mode 100644
index 09d9f0b..0000000
--- a/Tests/CoderTests/FunctionsTests/FlipTests.swift
+++ /dev/null
@@ -1,12 +0,0 @@
-import XCTest
-import Coder
-
-final class FlipTests: XCTestCase {
- func testFlip() {
- func append(s1: String, s2: String) -> String {
- s1 + s2
- }
-
- XCTAssert(flip(append)("1", "2") == "21")
- }
-}