Skip to content

Instantly share code, notes, and snippets.

@thinkclay
Created November 19, 2014 22:48
Show Gist options
  • Save thinkclay/2166f298ab4dc78c6736 to your computer and use it in GitHub Desktop.
Save thinkclay/2166f298ab4dc78c6736 to your computer and use it in GitHub Desktop.
// 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