Skip to content

Commit 1230006

Browse files
stephencelismbrandonw
authored andcommitted
Add "combining" and "their" (#33)
1 parent 5ac080d commit 1230006

File tree

5 files changed

+98
-3
lines changed

5 files changed

+98
-3
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM swift:4.0
1+
FROM swift:4.2
22

33
WORKDIR /package
44

Overture.playground/Pages/Basics.xcplaygroundpage/Contents.swift

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,31 @@ let capitalizeUserName = setUserName(capitalized(Locale(identifier: "en")))
3838
let setUserAge = prop(\User.age)
3939
let celebrateBirthday = setUserAge(incr)
4040

41-
with(User(name: "blob", age: 1), concat(
41+
let blob = User(name: "Blob", age: 42)
42+
43+
with(blob, concat(
4244
capitalizeUserName,
4345
celebrateBirthday
4446
))
47+
48+
let blobJr = with(blob, concat(
49+
mver(\.name) { $0 += ", Jr." },
50+
mver(\.age) { $0 -= 30 }
51+
))
52+
53+
let blobSr = with(blob, concat(
54+
mver(\.name) { $0 += ", Sr." },
55+
mver(\.age) { $0 += 30 }
56+
))
57+
58+
let users = [
59+
blob,
60+
blobJr,
61+
blobSr
62+
]
63+
64+
users.reduce(0, combining(get(\.age), +))
65+
users.reduce(into: 0, combining(get(\.age), +=))
66+
67+
users.sorted(by: their(get(\.age)))
68+
users.sorted(by: their(get(\.age), >))

Overture.xcodeproj/project.pbxproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
BF_230F9B6FE8E082DB44BD5B319B5EC8A6 /* Optional.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_59A44EA6FAD0A5B8E2EF8DE2AB4031A4 /* Optional.swift */; };
2525
BF_23E08DC7883D3F45E61CA14DBD5E5C65 /* Setters.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_44939FAD205372570B5B330488CA0FCA /* Setters.swift */; };
2626
BF_25DABD9A43C0A18D70D6948D4E19B3B8 /* Setters.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_44939FAD205372570B5B330488CA0FCA /* Setters.swift */; };
27+
BF_269D2F8C57F443470BE40FAA3F8809AE /* Combining.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_B0647A140F97B5E06558CF560D9B6F9F /* Combining.swift */; };
2728
BF_27190B2C2FE63C3EC797E0D43DE54251 /* Flip.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_40F0CB8AD68A516B6DFCE0B52294B90A /* Flip.swift */; };
2829
BF_2970219B3FC3D0AD835C16E55D071D50 /* Overture.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = FR_6F3FE2E50D3E47BB898203E4EBD149BF /* Overture.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
2930
BF_29B1493905E3862F8C7B1F509CFFA65C /* ZipSequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_675785456D0006C2F399C66CA7A3B7A5 /* ZipSequence.swift */; };
@@ -65,6 +66,7 @@
6566
BF_842B1BD199570421173717803C42F21D /* PipeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_894EF159C69BA0269E09F2FA70417454 /* PipeTests.swift */; };
6667
BF_8A3088E80AA00A443FDBC84B0D5B560D /* UncurryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_8CCF41C907508A12C07C9A17CFF59BFE /* UncurryTests.swift */; };
6768
BF_8B33C441D0B4437578A050002FB9B7B8 /* KeyPath.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_CED83466089E7A243C8C1FCF71E17B9F /* KeyPath.swift */; };
69+
BF_8E182E76550FF546537F2AF48E97595B /* Combining.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_B0647A140F97B5E06558CF560D9B6F9F /* Combining.swift */; };
6870
BF_904BA29B44C375543D6D15542535EA44 /* Curry.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_06406B14837AB1215EA9ABFB30C4EB34 /* Curry.swift */; };
6971
BF_921521576FF0DCBAC04FF81E0C35634C /* PipeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_894EF159C69BA0269E09F2FA70417454 /* PipeTests.swift */; };
7072
BF_97E6624C8964DC16CA053706AD44593C /* Chain.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_BD43B719463485B52151D8B6B3B26321 /* Chain.swift */; };
@@ -99,11 +101,13 @@
99101
BF_E17891411ABF13425EAEB0880365ECBF /* Compose.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_AA7E2B71688A3974A4073256E321E124 /* Compose.swift */; };
100102
BF_E283A25C25BAF326E3C9DB445B4405A2 /* PipeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_894EF159C69BA0269E09F2FA70417454 /* PipeTests.swift */; };
101103
BF_E50701AACBF9A7A9B8D47BB59A3F668C /* Overture.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FR_39D9F12A182E089A2B5F93163CD1EDF1 /* Overture.framework */; };
104+
BF_E6ED45F9DA2EF7CC726404AC04F3E9EF /* Combining.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_B0647A140F97B5E06558CF560D9B6F9F /* Combining.swift */; };
102105
BF_E7D851F98C1DD5DAC4B662FB8EDA20A2 /* Compose.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_AA7E2B71688A3974A4073256E321E124 /* Compose.swift */; };
103106
BF_ED286662266F635BE27959D1F6A6C525 /* ZipTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_8303D2CCD787D78072A064EF35F7AD07 /* ZipTests.swift */; };
104107
BF_ED3F92BE2587005B3D3651D4EB001EE1 /* Setters.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_44939FAD205372570B5B330488CA0FCA /* Setters.swift */; };
105108
BF_EDCAC53E731A364D955148CBF7C01189 /* UncurryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_8CCF41C907508A12C07C9A17CFF59BFE /* UncurryTests.swift */; };
106109
BF_EE01FEA596BA63D529AD6B7BFF9A9833 /* ComposeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_3428EF2F5FC60750C29A0277E5D0A24F /* ComposeTests.swift */; };
110+
BF_EE49218120AE6A09F0C30246A8F3202C /* Combining.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_B0647A140F97B5E06558CF560D9B6F9F /* Combining.swift */; };
107111
BF_F2E71F3ADB3E5E8276B25EB37F42E19F /* Overture.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = FR_4E2B58BC7C1A52C7E6773DCE69061656 /* Overture.framework */; };
108112
BF_F33DBFB4B987C0047D090B142DE749E3 /* Concat.swift in Sources */ = {isa = PBXBuildFile; fileRef = FR_3D48C5ADF5E20B0266DF3B87F7C91BC0 /* Concat.swift */; };
109113
BF_F35BE007A10306DDFDF6FE18A6FFBC8A /* Overture.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = FR_39D9F12A182E089A2B5F93163CD1EDF1 /* Overture.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
@@ -216,6 +220,7 @@
216220
FR_90F02BFDF494CDBE6C97DE492263A94B /* Overture.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Overture.framework; sourceTree = BUILT_PRODUCTS_DIR; };
217221
FR_AA7E2B71688A3974A4073256E321E124 /* Compose.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Compose.swift; sourceTree = "<group>"; };
218222
FR_ACAE1DD95EAB7CC17E032208F3990CB4 /* Pipe.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Pipe.swift; sourceTree = "<group>"; };
223+
FR_B0647A140F97B5E06558CF560D9B6F9F /* Combining.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Combining.swift; sourceTree = "<group>"; };
219224
FR_BD43B719463485B52151D8B6B3B26321 /* Chain.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Chain.swift; sourceTree = "<group>"; };
220225
FR_BE66E506058F0546B0DB3C896A4D2E78 /* Uncurry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Uncurry.swift; sourceTree = "<group>"; };
221226
FR_BE9328BCAACE2D9489E911C397146797 /* OvertureTests.xctest */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = wrapper.cfbundle; path = OvertureTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
@@ -305,6 +310,7 @@
305310
isa = PBXGroup;
306311
children = (
307312
FR_BD43B719463485B52151D8B6B3B26321 /* Chain.swift */,
313+
FR_B0647A140F97B5E06558CF560D9B6F9F /* Combining.swift */,
308314
FR_AA7E2B71688A3974A4073256E321E124 /* Compose.swift */,
309315
FR_3D48C5ADF5E20B0266DF3B87F7C91BC0 /* Concat.swift */,
310316
FR_06406B14837AB1215EA9ABFB30C4EB34 /* Curry.swift */,
@@ -515,6 +521,7 @@
515521
buildActionMask = 2147483647;
516522
files = (
517523
BF_97E6624C8964DC16CA053706AD44593C /* Chain.swift in Sources */,
524+
BF_E6ED45F9DA2EF7CC726404AC04F3E9EF /* Combining.swift in Sources */,
518525
BF_D75B5B389BB584D48DD3B74707AD1117 /* Compose.swift in Sources */,
519526
BF_2D763D9662AF81F11CAE2237BB6B8C50 /* Concat.swift in Sources */,
520527
BF_2BA7E2C18CD01F7432B63F3F8962C1FF /* Curry.swift in Sources */,
@@ -569,6 +576,7 @@
569576
buildActionMask = 2147483647;
570577
files = (
571578
BF_C185BBF408E02D23CFB8707C4243BA1F /* Chain.swift in Sources */,
579+
BF_EE49218120AE6A09F0C30246A8F3202C /* Combining.swift in Sources */,
572580
BF_06CD9D59D5DDD8EBA8A134A4EEF30773 /* Compose.swift in Sources */,
573581
BF_B2FFA3F34E6949896DF737B0FADACACD /* Concat.swift in Sources */,
574582
BF_904BA29B44C375543D6D15542535EA44 /* Curry.swift in Sources */,
@@ -591,6 +599,7 @@
591599
buildActionMask = 2147483647;
592600
files = (
593601
BF_B72E327228D972D3BF27D8C4360AE52E /* Chain.swift in Sources */,
602+
BF_8E182E76550FF546537F2AF48E97595B /* Combining.swift in Sources */,
594603
BF_E7D851F98C1DD5DAC4B662FB8EDA20A2 /* Compose.swift in Sources */,
595604
BF_C9E0218E7E989AFE30ED25E3A271E216 /* Concat.swift in Sources */,
596605
BF_7DC0A661822140B069850CA3FFB1A5AA /* Curry.swift in Sources */,
@@ -645,6 +654,7 @@
645654
buildActionMask = 2147483647;
646655
files = (
647656
BF_34525EA6AF600AF6FBCA3FF0C7E78C2E /* Chain.swift in Sources */,
657+
BF_269D2F8C57F443470BE40FAA3F8809AE /* Combining.swift in Sources */,
648658
BF_E17891411ABF13425EAEB0880365ECBF /* Compose.swift in Sources */,
649659
BF_F33DBFB4B987C0047D090B142DE749E3 /* Concat.swift in Sources */,
650660
BF_59A4B2E49BBC5165FBA540F0380AE2D0 /* Curry.swift in Sources */,

Sources/Overture/Combining.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
public func combining<Root, Value, NewValue>(
2+
_ getter: @escaping (Root) -> Value,
3+
_ combine: @escaping (Value, Value) -> NewValue
4+
)
5+
-> (Value, Root)
6+
-> NewValue {
7+
return { value, root in combine(value, getter(root)) }
8+
}
9+
10+
public func combining<Root, Value>(
11+
_ getter: @escaping (Root) -> Value,
12+
_ combine: @escaping (inout Value, Value) -> Void
13+
)
14+
-> (inout Value, Root)
15+
-> Void {
16+
return { value, root in combine(&value, getter(root)) }
17+
}
18+
19+
public func their<Root, Value, NewValue>(
20+
_ getter: @escaping (Root) -> Value,
21+
_ combining: @escaping (Value, Value) -> NewValue
22+
)
23+
-> (Root, Root) -> NewValue {
24+
return { combining(getter($0), getter($1)) }
25+
}
26+
27+
public func their<Root, Value: Comparable>(
28+
_ getter: @escaping (Root) -> Value
29+
)
30+
-> (Root, Root) -> Bool {
31+
return their(getter, <)
32+
}

Tests/LinuxMain.swift

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generated using Sourcery 0.10.1 — https://github.com/krzysztofzablocki/Sourcery
1+
// Generated using Sourcery 0.13.1 — https://github.com/krzysztofzablocki/Sourcery
22
// DO NOT EDIT
33

44
import XCTest
@@ -56,6 +56,11 @@ extension CurryTests {
5656
("testThrowing", testThrowing)
5757
]
5858
}
59+
extension FlipTests {
60+
static var allTests: [(String, (FlipTests) -> () throws -> Void)] = [
61+
("testFlip", testFlip)
62+
]
63+
}
5964
extension PipeTests {
6065
static var allTests: [(String, (PipeTests) -> () throws -> Void)] = [
6166
("testPipe2", testPipe2),
@@ -70,6 +75,12 @@ extension PipeTests {
7075
("testThrowingPipe6", testThrowingPipe6)
7176
]
7277
}
78+
extension UncurryTests {
79+
static var allTests: [(String, (UncurryTests) -> () throws -> Void)] = [
80+
("testUncurry", testUncurry),
81+
("testThrowing", testThrowing)
82+
]
83+
}
7384
extension WithTests {
7485
static var allTests: [(String, (WithTests) -> () throws -> Void)] = [
7586
("testWith", testWith),
@@ -78,14 +89,32 @@ extension WithTests {
7889
("testReferenceMutableWith", testReferenceMutableWith)
7990
]
8091
}
92+
extension ZipTests {
93+
static var allTests: [(String, (ZipTests) -> () throws -> Void)] = [
94+
("testZipOptional", testZipOptional),
95+
("testZipSequence", testZipSequence),
96+
("testZip2WithSequence", testZip2WithSequence),
97+
("testZip3WithSequence", testZip3WithSequence),
98+
("testZip4WithSequence", testZip4WithSequence),
99+
("testZip5WithSequence", testZip5WithSequence),
100+
("testZip6WithSequence", testZip6WithSequence),
101+
("testZip7WithSequence", testZip7WithSequence),
102+
("testZip8WithSequence", testZip8WithSequence),
103+
("testZip9WithSequence", testZip9WithSequence),
104+
("testZip10WithSequence", testZip10WithSequence)
105+
]
106+
}
81107

82108
// swiftlint:disable trailing_comma
83109
XCTMain([
84110
testCase(ChainTests.allTests),
85111
testCase(ComposeTests.allTests),
86112
testCase(ConcatTests.allTests),
87113
testCase(CurryTests.allTests),
114+
testCase(FlipTests.allTests),
88115
testCase(PipeTests.allTests),
116+
testCase(UncurryTests.allTests),
89117
testCase(WithTests.allTests),
118+
testCase(ZipTests.allTests),
90119
])
91120
// swiftlint:enable trailing_comma

0 commit comments

Comments
 (0)