Skip to content

Instantly share code, notes, and snippets.

@jarsen
Last active August 29, 2015 14:07
Show Gist options
  • Save jarsen/bc8ee2a9cc7d28e8d1c4 to your computer and use it in GitHub Desktop.
Save jarsen/bc8ee2a9cc7d28e8d1c4 to your computer and use it in GitHub Desktop.
how can I bind to a tuple in the closure?
func meanSquaredError(predictions: [Double], values: [Double]) -> Double {
let sum = reduce(Zip2(predictions, values), 0.0) { (acc, y) in
let diff = y.0 - y.1
return acc + (diff * diff)
}
return sum / Double(predictions.count)
}
// what I want is to bind the arguments in the closure to (acc, (yHat, y))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment