Skip to content

Commit

Permalink
Add update; fix ambiguity (#39)
Browse files Browse the repository at this point in the history
* Add update; fix ambiguity

* Fix

* remove nsmutableparagraph

* get rid of toggle
  • Loading branch information
stephencelis authored and mbrandonw committed Mar 7, 2019
1 parent b4c90bd commit 64d8a27
Show file tree
Hide file tree
Showing 13 changed files with 938 additions and 683 deletions.
1,228 changes: 629 additions & 599 deletions Overture.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions Overture.xcodeproj/xcshareddata/xcschemes/Overture_iOS.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NT_8274405197546C7088976F7D3DDE8DF1"
BlueprintIdentifier = "C986EA57938522DE23E8CA570CCC6C80"
BuildableName = "Overture.framework"
BlueprintName = "Overture_iOS"
ReferencedContainer = "container:Overture.xcodeproj">
Expand All @@ -32,7 +32,7 @@
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NT_DFC257B304396EB2F8621A597832188B"
BlueprintIdentifier = "32EB4906CEF837202537791A1D5496A8"
BuildableName = "OvertureTests.xctest"
BlueprintName = "OvertureTests_iOS"
ReferencedContainer = "container:Overture.xcodeproj">
Expand All @@ -42,7 +42,7 @@
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NT_8274405197546C7088976F7D3DDE8DF1"
BlueprintIdentifier = "C986EA57938522DE23E8CA570CCC6C80"
BuildableName = "Overture.framework"
BlueprintName = "Overture_iOS"
ReferencedContainer = "container:Overture.xcodeproj">
Expand All @@ -66,7 +66,7 @@
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NT_8274405197546C7088976F7D3DDE8DF1"
BlueprintIdentifier = "C986EA57938522DE23E8CA570CCC6C80"
BuildableName = "Overture.framework"
BlueprintName = "Overture_iOS"
ReferencedContainer = "container:Overture.xcodeproj">
Expand All @@ -87,7 +87,7 @@
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NT_8274405197546C7088976F7D3DDE8DF1"
BlueprintIdentifier = "C986EA57938522DE23E8CA570CCC6C80"
BuildableName = "Overture.framework"
BlueprintName = "Overture_iOS"
ReferencedContainer = "container:Overture.xcodeproj">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NT_10077D114ACEE363A2CEA6CF0B64E3F4"
BlueprintIdentifier = "1A9D4BE7E3ABBAE4B1CBB723464B111C"
BuildableName = "Overture.framework"
BlueprintName = "Overture_macOS"
ReferencedContainer = "container:Overture.xcodeproj">
Expand All @@ -32,7 +32,7 @@
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NT_B01ACAC5656934E5E3A34AF1BC07BFE1"
BlueprintIdentifier = "F137F6702BF7EF8181D5D0610F2C409E"
BuildableName = "OvertureTests.xctest"
BlueprintName = "OvertureTests_macOS"
ReferencedContainer = "container:Overture.xcodeproj">
Expand All @@ -42,7 +42,7 @@
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NT_10077D114ACEE363A2CEA6CF0B64E3F4"
BlueprintIdentifier = "1A9D4BE7E3ABBAE4B1CBB723464B111C"
BuildableName = "Overture.framework"
BlueprintName = "Overture_macOS"
ReferencedContainer = "container:Overture.xcodeproj">
Expand All @@ -66,7 +66,7 @@
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NT_10077D114ACEE363A2CEA6CF0B64E3F4"
BlueprintIdentifier = "1A9D4BE7E3ABBAE4B1CBB723464B111C"
BuildableName = "Overture.framework"
BlueprintName = "Overture_macOS"
ReferencedContainer = "container:Overture.xcodeproj">
Expand All @@ -87,7 +87,7 @@
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NT_10077D114ACEE363A2CEA6CF0B64E3F4"
BlueprintIdentifier = "1A9D4BE7E3ABBAE4B1CBB723464B111C"
BuildableName = "Overture.framework"
BlueprintName = "Overture_macOS"
ReferencedContainer = "container:Overture.xcodeproj">
Expand Down
10 changes: 5 additions & 5 deletions Overture.xcodeproj/xcshareddata/xcschemes/Overture_tvOS.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NT_5E226C14A867E37F073B5173927AAC2F"
BlueprintIdentifier = "A5595549A81068462256743E32D7E36D"
BuildableName = "Overture.framework"
BlueprintName = "Overture_tvOS"
ReferencedContainer = "container:Overture.xcodeproj">
Expand All @@ -32,7 +32,7 @@
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NT_A7EF3E9598E4FB2188DAD25389126465"
BlueprintIdentifier = "BF96F05D873EB74DC8204D6037969ED1"
BuildableName = "OvertureTests.xctest"
BlueprintName = "OvertureTests_tvOS"
ReferencedContainer = "container:Overture.xcodeproj">
Expand All @@ -42,7 +42,7 @@
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NT_5E226C14A867E37F073B5173927AAC2F"
BlueprintIdentifier = "A5595549A81068462256743E32D7E36D"
BuildableName = "Overture.framework"
BlueprintName = "Overture_tvOS"
ReferencedContainer = "container:Overture.xcodeproj">
Expand All @@ -66,7 +66,7 @@
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NT_5E226C14A867E37F073B5173927AAC2F"
BlueprintIdentifier = "A5595549A81068462256743E32D7E36D"
BuildableName = "Overture.framework"
BlueprintName = "Overture_tvOS"
ReferencedContainer = "container:Overture.xcodeproj">
Expand All @@ -87,7 +87,7 @@
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NT_5E226C14A867E37F073B5173927AAC2F"
BlueprintIdentifier = "A5595549A81068462256743E32D7E36D"
BuildableName = "Overture.framework"
BlueprintName = "Overture_tvOS"
ReferencedContainer = "container:Overture.xcodeproj">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NT_BDD2A196AF72DBE19A7C7D4CC1536658"
BlueprintIdentifier = "8B0FD87BBE58097B4A4B4BB493ACE221"
BuildableName = "Overture.framework"
BlueprintName = "Overture_watchOS"
ReferencedContainer = "container:Overture.xcodeproj">
Expand All @@ -32,7 +32,7 @@
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NT_597175CE766F23764FEFFAF48905C32F"
BlueprintIdentifier = "F256AD3DF59DF20D3BDA368BF2F8E39A"
BuildableName = "OvertureTests.xctest"
BlueprintName = "OvertureTests_watchOS"
ReferencedContainer = "container:Overture.xcodeproj">
Expand All @@ -42,7 +42,7 @@
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NT_BDD2A196AF72DBE19A7C7D4CC1536658"
BlueprintIdentifier = "8B0FD87BBE58097B4A4B4BB493ACE221"
BuildableName = "Overture.framework"
BlueprintName = "Overture_watchOS"
ReferencedContainer = "container:Overture.xcodeproj">
Expand All @@ -66,7 +66,7 @@
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NT_BDD2A196AF72DBE19A7C7D4CC1536658"
BlueprintIdentifier = "8B0FD87BBE58097B4A4B4BB493ACE221"
BuildableName = "Overture.framework"
BlueprintName = "Overture_watchOS"
ReferencedContainer = "container:Overture.xcodeproj">
Expand All @@ -87,7 +87,7 @@
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NT_BDD2A196AF72DBE19A7C7D4CC1536658"
BlueprintIdentifier = "8B0FD87BBE58097B4A4B4BB493ACE221"
BuildableName = "Overture.framework"
BlueprintName = "Overture_watchOS"
ReferencedContainer = "container:Overture.xcodeproj">
Expand Down
8 changes: 5 additions & 3 deletions Sources/Overture/KeyPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ public func mprop<Root, Value>(
_ keyPath: ReferenceWritableKeyPath<Root, Value>
)
-> (@escaping (Value) -> Void)
-> (Root) -> Void {
-> (Root) -> Void
where Value: AnyObject {

return { update in
{ root in
Expand All @@ -116,11 +117,12 @@ public func mprop<Root, Value>(
/// - keyPath: A reference-writable key path.
/// - update: An update function for a given value.
/// - Returns: A reference-mutable setter function.
public func mver<Root, Value>(
public func mverObject<Root, Value>(
_ keyPath: ReferenceWritableKeyPath<Root, Value>,
_ update: @escaping (Value) -> Void
)
-> (Root) -> Void {
-> (Root) -> Void
where Value: AnyObject {

return mprop(keyPath)(update)
}
Expand Down
26 changes: 22 additions & 4 deletions Sources/Overture/Setters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,28 @@ public func mver<S, A>(
/// - setter: A reference-mutable setter function.
/// - f: A mutable value transform function.
/// - Returns: A reference-mutable root transform function.
public func mver<S: AnyObject, A>(
public func mver<S, A>(
_ setter: (@escaping (inout A) -> Void) -> (S) -> Void,
_ f: @escaping (inout A) -> Void
)
-> (S) -> Void {
-> (S) -> Void
where S: AnyObject {

return setter(f)
}

/// Applies a reference-mutable value transformation to a reference-mutable setter function.
///
/// - Parameters:
/// - setter: A reference-mutable setter function.
/// - f: A mutable value transform function.
/// - Returns: A reference-mutable root transform function.
public func mver<S, A>(
_ setter: (@escaping (A) -> Void) -> (S) -> Void,
_ f: @escaping (A) -> Void
)
-> (S) -> Void
where S: AnyObject, A: AnyObject {

return setter(f)
}
Expand All @@ -82,11 +99,12 @@ public func mut<S, A>(
/// - setter: An mutable setter function.
/// - value: A new value.
/// - Returns: A reference-mutable root transform function.
public func mut<S: AnyObject, A>(
public func mut<S, A>(
_ setter: (@escaping (inout A) -> Void) -> (S) -> Void,
_ value: A
)
-> (S) -> Void {
-> (S) -> Void
where S: AnyObject {

return mver(setter) { $0 = value }
}
72 changes: 72 additions & 0 deletions Sources/Overture/Update.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

/// Left-to-right, in-place function application.
///
/// - Parameters:
/// - a: A mutable value.
/// - fs: In-out functions.
/// - Note: This function is commonly seen in operator form as "pipe-forward", `|>`.
public func update<A>(_ a: inout A, _ fs: ((inout A) -> Void)...) {
fs.forEach { f in f(&a) }
}

/// Left-to-right, in-place throwing function application.
///
/// - Parameters:
/// - a: A mutable value.
/// - fs: In-out functions.
/// - Note: This function is commonly seen in operator form as "pipe-forward", `|>`.
public func update<A>(_ a: inout A, _ fs: ((inout A) throws -> Void)...) throws {
try fs.forEach { f in try f(&a) }
}

/// Left-to-right, value-mutable function application.
///
/// - Parameters:
/// - a: A value.
/// - fs: In-out functions.
/// - Returns: The result of `f` applied to `a`.
/// - Note: This function is commonly seen in operator form as "pipe-forward", `|>`.
public func update<A>(_ a: A, _ fs: ((inout A) -> Void)...) -> A {
var a = a
fs.forEach { f in f(&a) }
return a
}

/// Left-to-right, value-mutable, throwing function application.
///
/// - Parameters:
/// - a: A value.
/// - fs: In-out functions.
/// - Returns: The result of `f` applied to `a`.
/// - Note: This function is commonly seen in operator form as "pipe-forward", `|>`.
public func update<A>(_ a: A, _ fs: ((inout A) throws -> Void)...) throws -> A {
var a = a
try fs.forEach { f in try f(&a) }
return a
}

/// Left-to-right, reference-mutable function application.
///
/// - Parameters:
/// - a: A mutable value.
/// - f: An function from `A` to `Void`.
/// - Returns: The result of `f` applied to `a`.
/// - Note: This function is commonly seen in operator form as "pipe-forward", `|>`.
@discardableResult
public func updateObject<A: AnyObject>(_ a: A, _ fs: ((A) -> Void)...) -> A {
fs.forEach { f in f(a) }
return a
}

/// Left-to-right, reference-mutable, throwing function application.
///
/// - Parameters:
/// - a: A mutable value.
/// - f: An function from `A` to `Void`.
/// - Returns: The result of `f` applied to `a`.
/// - Note: This function is commonly seen in operator form as "pipe-forward", `|>`.
@discardableResult
public func updateObject<A: AnyObject>(_ a: A, _ fs: ((A) throws -> Void)...) throws -> A {
try fs.forEach { f in try f(a) }
return a
}
36 changes: 0 additions & 36 deletions Sources/Overture/With.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,3 @@
public func with<A, B>(_ a: A, _ f: (A) throws -> B) rethrows -> B {
return try f(a)
}

/// Left-to-right, in-place function application.
///
/// - Parameters:
/// - a: A mutable value.
/// - f: An in-out function.
/// - Note: This function is commonly seen in operator form as "pipe-forward", `|>`.
public func with<A>(_ a: inout A, _ f: (inout A) throws -> Void) rethrows {
try f(&a)
}

/// Left-to-right, value-mutable function application.
///
/// - Parameters:
/// - a: A value.
/// - f: An in-out function.
/// - Returns: The result of `f` applied to `a`.
/// - Note: This function is commonly seen in operator form as "pipe-forward", `|>`.
public func with<A>(_ a: A, _ f: (inout A) throws -> Void) rethrows -> A {
var a = a
try f(&a)
return a
}

/// Left-to-right, reference-mutable function application.
///
/// - Parameters:
/// - a: A mutable value.
/// - f: An function from `A` to `Void`.
/// - Returns: The result of `f` applied to `a`.
/// - Note: This function is commonly seen in operator form as "pipe-forward", `|>`.
@discardableResult
public func with<A: AnyObject>(_ a: A, _ f: (A) throws -> Void) rethrows -> A {
try f(a)
return a
}
Loading

0 comments on commit 64d8a27

Please sign in to comment.