Skip to content

Files

Latest commit

 

History

History
25 lines (13 loc) · 351 Bytes

flatmap_over_map_reduce.md

File metadata and controls

25 lines (13 loc) · 351 Bytes

Pattern: Use of map instead of flatMap

Issue: -

Description

Prefer flatMap over map followed by reduce([], +).

Examples of correct code:

let foo = bar.map { $0.count }.reduce(0, +)


let foo = bar.flatMap { $0.array }

Examples of incorrect code:

let foo = bar.map { $0.array }.reduce([], +)