Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add update; fix ambiguity #39

Merged
merged 5 commits into from
Mar 7, 2019
Merged

Add update; fix ambiguity #39

merged 5 commits into from
Mar 7, 2019

Conversation

stephencelis
Copy link
Member

This should fix #30, though let's discuss naming...

@@ -14,7 +14,7 @@
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "NT_8274405197546C7088976F7D3DDE8DF1"
BlueprintIdentifier = "C986EA57938522DE23E8CA570CCC6C80"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated XcodeGen...

@@ -117,10 +118,11 @@ public func mprop<Root, Value>(
/// - update: An update function for a given value.
/// - Returns: A reference-mutable setter function.
public func mver<Root, Value>(
_ keyPath: ReferenceWritableKeyPath<Root, Value>,
reference keyPath: ReferenceWritableKeyPath<Root, Value>,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one overload of mver from a reference to a reference causes ambiguity with the inout version when using inline closures...

@@ -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>(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think trailing where is preferred now...

@@ -18,8 +18,18 @@ public func with<A, B>(_ a: A, _ f: (A) throws -> B) rethrows -> B {
/// - 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)
public func update<A>(_ a: inout A, _ fs: ((inout A) -> Void)...) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with is now just for (A, (A) -> B) -> B.

@@ -43,7 +66,20 @@ public func with<A>(_ a: A, _ f: (inout A) throws -> Void) rethrows -> A {
/// - 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)
public func update<A: AnyObject>(reference a: A, _ fs: ((A) -> Void)...) -> A {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This overload is also for fixing ambiguity with the inout version when using inline closures...

@stephencelis
Copy link
Member Author

@mbrandonw Do you have a better idea for naming those reference overloads?

  • update(reference:)
  • mver(reference:)

@mbrandonw mbrandonw merged commit 64d8a27 into master Mar 7, 2019
@mbrandonw mbrandonw deleted the update branch March 7, 2019 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ambiguous use of with
2 participants