Skip to content

Commit 64d8a27

Browse files
stephencelismbrandonw
authored andcommitted
Add update; fix ambiguity (#39)
* Add update; fix ambiguity * Fix * remove nsmutableparagraph * get rid of toggle
1 parent b4c90bd commit 64d8a27

13 files changed

+938
-683
lines changed

Overture.xcodeproj/project.pbxproj

Lines changed: 629 additions & 599 deletions
Large diffs are not rendered by default.

Overture.xcodeproj/xcshareddata/xcschemes/Overture_iOS.xcscheme

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
buildForAnalyzing = "YES">
1515
<BuildableReference
1616
BuildableIdentifier = "primary"
17-
BlueprintIdentifier = "NT_8274405197546C7088976F7D3DDE8DF1"
17+
BlueprintIdentifier = "C986EA57938522DE23E8CA570CCC6C80"
1818
BuildableName = "Overture.framework"
1919
BlueprintName = "Overture_iOS"
2020
ReferencedContainer = "container:Overture.xcodeproj">
@@ -32,7 +32,7 @@
3232
skipped = "NO">
3333
<BuildableReference
3434
BuildableIdentifier = "primary"
35-
BlueprintIdentifier = "NT_DFC257B304396EB2F8621A597832188B"
35+
BlueprintIdentifier = "32EB4906CEF837202537791A1D5496A8"
3636
BuildableName = "OvertureTests.xctest"
3737
BlueprintName = "OvertureTests_iOS"
3838
ReferencedContainer = "container:Overture.xcodeproj">
@@ -42,7 +42,7 @@
4242
<MacroExpansion>
4343
<BuildableReference
4444
BuildableIdentifier = "primary"
45-
BlueprintIdentifier = "NT_8274405197546C7088976F7D3DDE8DF1"
45+
BlueprintIdentifier = "C986EA57938522DE23E8CA570CCC6C80"
4646
BuildableName = "Overture.framework"
4747
BlueprintName = "Overture_iOS"
4848
ReferencedContainer = "container:Overture.xcodeproj">
@@ -66,7 +66,7 @@
6666
<MacroExpansion>
6767
<BuildableReference
6868
BuildableIdentifier = "primary"
69-
BlueprintIdentifier = "NT_8274405197546C7088976F7D3DDE8DF1"
69+
BlueprintIdentifier = "C986EA57938522DE23E8CA570CCC6C80"
7070
BuildableName = "Overture.framework"
7171
BlueprintName = "Overture_iOS"
7272
ReferencedContainer = "container:Overture.xcodeproj">
@@ -87,7 +87,7 @@
8787
runnableDebuggingMode = "0">
8888
<BuildableReference
8989
BuildableIdentifier = "primary"
90-
BlueprintIdentifier = "NT_8274405197546C7088976F7D3DDE8DF1"
90+
BlueprintIdentifier = "C986EA57938522DE23E8CA570CCC6C80"
9191
BuildableName = "Overture.framework"
9292
BlueprintName = "Overture_iOS"
9393
ReferencedContainer = "container:Overture.xcodeproj">

Overture.xcodeproj/xcshareddata/xcschemes/Overture_macOS.xcscheme

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
buildForAnalyzing = "YES">
1515
<BuildableReference
1616
BuildableIdentifier = "primary"
17-
BlueprintIdentifier = "NT_10077D114ACEE363A2CEA6CF0B64E3F4"
17+
BlueprintIdentifier = "1A9D4BE7E3ABBAE4B1CBB723464B111C"
1818
BuildableName = "Overture.framework"
1919
BlueprintName = "Overture_macOS"
2020
ReferencedContainer = "container:Overture.xcodeproj">
@@ -32,7 +32,7 @@
3232
skipped = "NO">
3333
<BuildableReference
3434
BuildableIdentifier = "primary"
35-
BlueprintIdentifier = "NT_B01ACAC5656934E5E3A34AF1BC07BFE1"
35+
BlueprintIdentifier = "F137F6702BF7EF8181D5D0610F2C409E"
3636
BuildableName = "OvertureTests.xctest"
3737
BlueprintName = "OvertureTests_macOS"
3838
ReferencedContainer = "container:Overture.xcodeproj">
@@ -42,7 +42,7 @@
4242
<MacroExpansion>
4343
<BuildableReference
4444
BuildableIdentifier = "primary"
45-
BlueprintIdentifier = "NT_10077D114ACEE363A2CEA6CF0B64E3F4"
45+
BlueprintIdentifier = "1A9D4BE7E3ABBAE4B1CBB723464B111C"
4646
BuildableName = "Overture.framework"
4747
BlueprintName = "Overture_macOS"
4848
ReferencedContainer = "container:Overture.xcodeproj">
@@ -66,7 +66,7 @@
6666
<MacroExpansion>
6767
<BuildableReference
6868
BuildableIdentifier = "primary"
69-
BlueprintIdentifier = "NT_10077D114ACEE363A2CEA6CF0B64E3F4"
69+
BlueprintIdentifier = "1A9D4BE7E3ABBAE4B1CBB723464B111C"
7070
BuildableName = "Overture.framework"
7171
BlueprintName = "Overture_macOS"
7272
ReferencedContainer = "container:Overture.xcodeproj">
@@ -87,7 +87,7 @@
8787
runnableDebuggingMode = "0">
8888
<BuildableReference
8989
BuildableIdentifier = "primary"
90-
BlueprintIdentifier = "NT_10077D114ACEE363A2CEA6CF0B64E3F4"
90+
BlueprintIdentifier = "1A9D4BE7E3ABBAE4B1CBB723464B111C"
9191
BuildableName = "Overture.framework"
9292
BlueprintName = "Overture_macOS"
9393
ReferencedContainer = "container:Overture.xcodeproj">

Overture.xcodeproj/xcshareddata/xcschemes/Overture_tvOS.xcscheme

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
buildForAnalyzing = "YES">
1515
<BuildableReference
1616
BuildableIdentifier = "primary"
17-
BlueprintIdentifier = "NT_5E226C14A867E37F073B5173927AAC2F"
17+
BlueprintIdentifier = "A5595549A81068462256743E32D7E36D"
1818
BuildableName = "Overture.framework"
1919
BlueprintName = "Overture_tvOS"
2020
ReferencedContainer = "container:Overture.xcodeproj">
@@ -32,7 +32,7 @@
3232
skipped = "NO">
3333
<BuildableReference
3434
BuildableIdentifier = "primary"
35-
BlueprintIdentifier = "NT_A7EF3E9598E4FB2188DAD25389126465"
35+
BlueprintIdentifier = "BF96F05D873EB74DC8204D6037969ED1"
3636
BuildableName = "OvertureTests.xctest"
3737
BlueprintName = "OvertureTests_tvOS"
3838
ReferencedContainer = "container:Overture.xcodeproj">
@@ -42,7 +42,7 @@
4242
<MacroExpansion>
4343
<BuildableReference
4444
BuildableIdentifier = "primary"
45-
BlueprintIdentifier = "NT_5E226C14A867E37F073B5173927AAC2F"
45+
BlueprintIdentifier = "A5595549A81068462256743E32D7E36D"
4646
BuildableName = "Overture.framework"
4747
BlueprintName = "Overture_tvOS"
4848
ReferencedContainer = "container:Overture.xcodeproj">
@@ -66,7 +66,7 @@
6666
<MacroExpansion>
6767
<BuildableReference
6868
BuildableIdentifier = "primary"
69-
BlueprintIdentifier = "NT_5E226C14A867E37F073B5173927AAC2F"
69+
BlueprintIdentifier = "A5595549A81068462256743E32D7E36D"
7070
BuildableName = "Overture.framework"
7171
BlueprintName = "Overture_tvOS"
7272
ReferencedContainer = "container:Overture.xcodeproj">
@@ -87,7 +87,7 @@
8787
runnableDebuggingMode = "0">
8888
<BuildableReference
8989
BuildableIdentifier = "primary"
90-
BlueprintIdentifier = "NT_5E226C14A867E37F073B5173927AAC2F"
90+
BlueprintIdentifier = "A5595549A81068462256743E32D7E36D"
9191
BuildableName = "Overture.framework"
9292
BlueprintName = "Overture_tvOS"
9393
ReferencedContainer = "container:Overture.xcodeproj">

Overture.xcodeproj/xcshareddata/xcschemes/Overture_watchOS.xcscheme

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
buildForAnalyzing = "YES">
1515
<BuildableReference
1616
BuildableIdentifier = "primary"
17-
BlueprintIdentifier = "NT_BDD2A196AF72DBE19A7C7D4CC1536658"
17+
BlueprintIdentifier = "8B0FD87BBE58097B4A4B4BB493ACE221"
1818
BuildableName = "Overture.framework"
1919
BlueprintName = "Overture_watchOS"
2020
ReferencedContainer = "container:Overture.xcodeproj">
@@ -32,7 +32,7 @@
3232
skipped = "NO">
3333
<BuildableReference
3434
BuildableIdentifier = "primary"
35-
BlueprintIdentifier = "NT_597175CE766F23764FEFFAF48905C32F"
35+
BlueprintIdentifier = "F256AD3DF59DF20D3BDA368BF2F8E39A"
3636
BuildableName = "OvertureTests.xctest"
3737
BlueprintName = "OvertureTests_watchOS"
3838
ReferencedContainer = "container:Overture.xcodeproj">
@@ -42,7 +42,7 @@
4242
<MacroExpansion>
4343
<BuildableReference
4444
BuildableIdentifier = "primary"
45-
BlueprintIdentifier = "NT_BDD2A196AF72DBE19A7C7D4CC1536658"
45+
BlueprintIdentifier = "8B0FD87BBE58097B4A4B4BB493ACE221"
4646
BuildableName = "Overture.framework"
4747
BlueprintName = "Overture_watchOS"
4848
ReferencedContainer = "container:Overture.xcodeproj">
@@ -66,7 +66,7 @@
6666
<MacroExpansion>
6767
<BuildableReference
6868
BuildableIdentifier = "primary"
69-
BlueprintIdentifier = "NT_BDD2A196AF72DBE19A7C7D4CC1536658"
69+
BlueprintIdentifier = "8B0FD87BBE58097B4A4B4BB493ACE221"
7070
BuildableName = "Overture.framework"
7171
BlueprintName = "Overture_watchOS"
7272
ReferencedContainer = "container:Overture.xcodeproj">
@@ -87,7 +87,7 @@
8787
runnableDebuggingMode = "0">
8888
<BuildableReference
8989
BuildableIdentifier = "primary"
90-
BlueprintIdentifier = "NT_BDD2A196AF72DBE19A7C7D4CC1536658"
90+
BlueprintIdentifier = "8B0FD87BBE58097B4A4B4BB493ACE221"
9191
BuildableName = "Overture.framework"
9292
BlueprintName = "Overture_watchOS"
9393
ReferencedContainer = "container:Overture.xcodeproj">

Sources/Overture/KeyPath.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ public func mprop<Root, Value>(
101101
_ keyPath: ReferenceWritableKeyPath<Root, Value>
102102
)
103103
-> (@escaping (Value) -> Void)
104-
-> (Root) -> Void {
104+
-> (Root) -> Void
105+
where Value: AnyObject {
105106

106107
return { update in
107108
{ root in
@@ -116,11 +117,12 @@ public func mprop<Root, Value>(
116117
/// - keyPath: A reference-writable key path.
117118
/// - update: An update function for a given value.
118119
/// - Returns: A reference-mutable setter function.
119-
public func mver<Root, Value>(
120+
public func mverObject<Root, Value>(
120121
_ keyPath: ReferenceWritableKeyPath<Root, Value>,
121122
_ update: @escaping (Value) -> Void
122123
)
123-
-> (Root) -> Void {
124+
-> (Root) -> Void
125+
where Value: AnyObject {
124126

125127
return mprop(keyPath)(update)
126128
}

Sources/Overture/Setters.swift

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,28 @@ public func mver<S, A>(
5252
/// - setter: A reference-mutable setter function.
5353
/// - f: A mutable value transform function.
5454
/// - Returns: A reference-mutable root transform function.
55-
public func mver<S: AnyObject, A>(
55+
public func mver<S, A>(
5656
_ setter: (@escaping (inout A) -> Void) -> (S) -> Void,
5757
_ f: @escaping (inout A) -> Void
5858
)
59-
-> (S) -> Void {
59+
-> (S) -> Void
60+
where S: AnyObject {
61+
62+
return setter(f)
63+
}
64+
65+
/// Applies a reference-mutable value transformation to a reference-mutable setter function.
66+
///
67+
/// - Parameters:
68+
/// - setter: A reference-mutable setter function.
69+
/// - f: A mutable value transform function.
70+
/// - Returns: A reference-mutable root transform function.
71+
public func mver<S, A>(
72+
_ setter: (@escaping (A) -> Void) -> (S) -> Void,
73+
_ f: @escaping (A) -> Void
74+
)
75+
-> (S) -> Void
76+
where S: AnyObject, A: AnyObject {
6077

6178
return setter(f)
6279
}
@@ -82,11 +99,12 @@ public func mut<S, A>(
8299
/// - setter: An mutable setter function.
83100
/// - value: A new value.
84101
/// - Returns: A reference-mutable root transform function.
85-
public func mut<S: AnyObject, A>(
102+
public func mut<S, A>(
86103
_ setter: (@escaping (inout A) -> Void) -> (S) -> Void,
87104
_ value: A
88105
)
89-
-> (S) -> Void {
106+
-> (S) -> Void
107+
where S: AnyObject {
90108

91109
return mver(setter) { $0 = value }
92110
}

Sources/Overture/Update.swift

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
2+
/// Left-to-right, in-place function application.
3+
///
4+
/// - Parameters:
5+
/// - a: A mutable value.
6+
/// - fs: In-out functions.
7+
/// - Note: This function is commonly seen in operator form as "pipe-forward", `|>`.
8+
public func update<A>(_ a: inout A, _ fs: ((inout A) -> Void)...) {
9+
fs.forEach { f in f(&a) }
10+
}
11+
12+
/// Left-to-right, in-place throwing function application.
13+
///
14+
/// - Parameters:
15+
/// - a: A mutable value.
16+
/// - fs: In-out functions.
17+
/// - Note: This function is commonly seen in operator form as "pipe-forward", `|>`.
18+
public func update<A>(_ a: inout A, _ fs: ((inout A) throws -> Void)...) throws {
19+
try fs.forEach { f in try f(&a) }
20+
}
21+
22+
/// Left-to-right, value-mutable function application.
23+
///
24+
/// - Parameters:
25+
/// - a: A value.
26+
/// - fs: In-out functions.
27+
/// - Returns: The result of `f` applied to `a`.
28+
/// - Note: This function is commonly seen in operator form as "pipe-forward", `|>`.
29+
public func update<A>(_ a: A, _ fs: ((inout A) -> Void)...) -> A {
30+
var a = a
31+
fs.forEach { f in f(&a) }
32+
return a
33+
}
34+
35+
/// Left-to-right, value-mutable, throwing function application.
36+
///
37+
/// - Parameters:
38+
/// - a: A value.
39+
/// - fs: In-out functions.
40+
/// - Returns: The result of `f` applied to `a`.
41+
/// - Note: This function is commonly seen in operator form as "pipe-forward", `|>`.
42+
public func update<A>(_ a: A, _ fs: ((inout A) throws -> Void)...) throws -> A {
43+
var a = a
44+
try fs.forEach { f in try f(&a) }
45+
return a
46+
}
47+
48+
/// Left-to-right, reference-mutable function application.
49+
///
50+
/// - Parameters:
51+
/// - a: A mutable value.
52+
/// - f: An function from `A` to `Void`.
53+
/// - Returns: The result of `f` applied to `a`.
54+
/// - Note: This function is commonly seen in operator form as "pipe-forward", `|>`.
55+
@discardableResult
56+
public func updateObject<A: AnyObject>(_ a: A, _ fs: ((A) -> Void)...) -> A {
57+
fs.forEach { f in f(a) }
58+
return a
59+
}
60+
61+
/// Left-to-right, reference-mutable, throwing function application.
62+
///
63+
/// - Parameters:
64+
/// - a: A mutable value.
65+
/// - f: An function from `A` to `Void`.
66+
/// - Returns: The result of `f` applied to `a`.
67+
/// - Note: This function is commonly seen in operator form as "pipe-forward", `|>`.
68+
@discardableResult
69+
public func updateObject<A: AnyObject>(_ a: A, _ fs: ((A) throws -> Void)...) throws -> A {
70+
try fs.forEach { f in try f(a) }
71+
return a
72+
}

Sources/Overture/With.swift

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,3 @@
1111
public func with<A, B>(_ a: A, _ f: (A) throws -> B) rethrows -> B {
1212
return try f(a)
1313
}
14-
15-
/// Left-to-right, in-place function application.
16-
///
17-
/// - Parameters:
18-
/// - a: A mutable value.
19-
/// - f: An in-out function.
20-
/// - Note: This function is commonly seen in operator form as "pipe-forward", `|>`.
21-
public func with<A>(_ a: inout A, _ f: (inout A) throws -> Void) rethrows {
22-
try f(&a)
23-
}
24-
25-
/// Left-to-right, value-mutable function application.
26-
///
27-
/// - Parameters:
28-
/// - a: A value.
29-
/// - f: An in-out function.
30-
/// - Returns: The result of `f` applied to `a`.
31-
/// - Note: This function is commonly seen in operator form as "pipe-forward", `|>`.
32-
public func with<A>(_ a: A, _ f: (inout A) throws -> Void) rethrows -> A {
33-
var a = a
34-
try f(&a)
35-
return a
36-
}
37-
38-
/// Left-to-right, reference-mutable function application.
39-
///
40-
/// - Parameters:
41-
/// - a: A mutable value.
42-
/// - f: An function from `A` to `Void`.
43-
/// - Returns: The result of `f` applied to `a`.
44-
/// - Note: This function is commonly seen in operator form as "pipe-forward", `|>`.
45-
@discardableResult
46-
public func with<A: AnyObject>(_ a: A, _ f: (A) throws -> Void) rethrows -> A {
47-
try f(a)
48-
return a
49-
}

0 commit comments

Comments
 (0)