Created
November 19, 2014 22:48
-
-
Save thinkclay/2166f298ab4dc78c6736 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // As an example, let's look at a reduction that creates a total sum | |
| // of an array of Floats with a different approaches, all with the same outcome: | |
| let total: [Float] -> Float = { $0.reduce(0, combine: +) } | |
| let total = transactions.reduce(0, {$0 + $1}) | |
| // It's easy to swap out operators to make it a multiplication, division, | |
| // or some other custom block execution. | |
| // Here we want to know if an entire list of booleans is true: | |
| let all_or_nothing: [Bool] -> Bool = { | |
| $0.reduce(true, combine: { $0 && $1 } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment