- Swift Functional Programming(Second Edition)
- Dr. Fatih Nayebi
- 98字
- 2021-07-02 23:54:27
The reduce function
The reduce function is a higher-order function that reduces an array to a single value. It takes two parameters: a starting value and a function, which takes a running total and an element of the arrays as parameters and returns a new running total. Consider the following example:
let total = numbers.reduce(0) { $0 + $1 }
The map, filter, and reduce functions accept a closure as the last parameter, so we were able to use the trailing closure syntax. These higher-order functions will be covered in detail in Chapter 6, Map, Filter, and Reduce.
推薦閱讀
- Python數(shù)據(jù)分析與挖掘?qū)崙?zhàn)
- Word 2010中文版完全自學(xué)手冊(cè)
- 信息系統(tǒng)與數(shù)據(jù)科學(xué)
- Spark快速大數(shù)據(jù)分析(第2版)
- Voice Application Development for Android
- 數(shù)據(jù)庫(kù)系統(tǒng)原理及應(yīng)用教程(第4版)
- Hadoop大數(shù)據(jù)實(shí)戰(zhàn)權(quán)威指南(第2版)
- MATLAB Graphics and Data Visualization Cookbook
- R語(yǔ)言數(shù)據(jù)挖掘
- Mastering LOB Development for Silverlight 5:A Case Study in Action
- 二進(jìn)制分析實(shí)戰(zhàn)
- Filecoin原理與實(shí)現(xiàn)
- 數(shù)據(jù)庫(kù)應(yīng)用系統(tǒng)技術(shù)
- Microsoft Dynamics NAV 2015 Professional Reporting
- Cognitive Computing with IBM Watson