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
extension Sequence { | |
func reduce<Result>( | |
_ initialResult: Result, | |
_ nextPartialResult: (Result, Self.Iterator.Element) throws -> Result, | |
until conditionPassForResult: (Result) -> Bool | |
) rethrows -> Result { | |
return try reduce( | |
initialResult, | |
{ |
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
(1 ... 5).reduce( | |
0, | |
+, | |
until: { partialSum in partialSum > 5 } | |
) // Returns 6 |
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
extension Sequence { | |
func reduce<Result>( | |
_ initialResult: Result, | |
_ nextPartialResult: (Result, Self.Iterator.Element) throws -> Result, | |
until conditionPassFor: (Result, Self.Iterator.Element) -> Bool | |
) rethrows -> Result { | |
do { | |
return try reduce( | |
initialResult, |
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
extension Sequence { | |
func reduce<Result>( | |
_ initialResult: Result, | |
_ nextPartialResult: (Result, Self.Iterator.Element) throws -> Result, | |
while conditionPassFor: (Result, Self.Iterator.Element) -> Bool | |
) rethrows -> Result { | |
do { | |
return try reduce( | |
initialResult, |
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
(1 ... 5).reduce( | |
0, | |
+, | |
while: { partialSum, _ in partialSum < 5 } | |
) // Returns 3 |
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
private struct BreakConditionError<Result>: Error { | |
let result: Result | |
} |
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
func show(withAnimation animation: Animation?) |
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
object.show(withAnimation: nil) |
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
enum WrappedAnimation { | |
case fromBottom // Anonymous nil before | |
case specific(Animation) | |
} |
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
object.show(withWrappedAnimation: .fromBottom) |