> For the complete documentation index, see [llms.txt](https://sagar-r-kothari.gitbook.io/blog/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sagar-r-kothari.gitbook.io/blog/_posts/2020-02-08-swift-reduce-example.md).

# 2020-02-08-Swift-Reduce-Example

```swift
let items = [10, 20, 5324, 23, 2309]

// readable way
let total = items.reduce(0) { (result, nextValue) -> Int in
    return result + nextValue
}

// encrypted way :P
let anotherTotal = items.reduce(0, { $0 + $1 })

print("Total is \(total)")
```
