Mastering macOS Programming
上QQ阅读APP看书,第一时间看更新

Chaining

We can also chain applications:

let results2 = collections.flatMap({$0}).filter({ $0 <10 }) 

Again, see if you can work out what type and value results2 will have, before running the code.

Knowing when to stop:

Like so many things in code writing, the extent to which you can reasonably chain and nest such statements should depend on code readability. It's not very smart to write code that looks very clever, if nobody can understand it.