Lambdas • Lesson 46/100+50 XP

Fold & Reduce

Aggregate collection values

📚
Learn
💻
Code
Quiz
🏆
Practice
Complete

📚 Lý thuyết

**fold** và **reduce** tổng hợp collection thành 1 giá trị. **reduce { acc, elem -> }:** - Bắt đầu từ phần tử đầu - Throws exception nếu empty **fold(initial) { acc, elem -> }:** - Bắt đầu từ giá trị cho trước - An toàn với empty collection