Last active
January 8, 2019 14:29
-
-
Save lukewakeford/3afb3537fd1346504078e805d5f659e5 to your computer and use it in GitHub Desktop.
Reduce Playground Example
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
import UIKit | |
struct product { | |
var price:Int? | |
var name:String | |
} | |
let array = [ | |
product(price: 100, name: "First"), | |
product(price: nil, name: "Second"), | |
product(price: 300, name: "Thrid") | |
] | |
let numberSum = array.reduce(0, { x, y in | |
x + (y.price ?? 0) | |
}) | |
print(numberSum) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment