-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add update; fix ambiguity * Fix * remove nsmutableparagraph * get rid of toggle
- Loading branch information
1 parent
b4c90bd
commit 64d8a27
Showing
13 changed files
with
938 additions
and
683 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.