Swift Tricks: Searching for Objects by Type

Performing operations such as map or flatmap on large collections can be expensive. Luckily, Swift provides lazy collections. Using a lazy collection, all operations are delayed until we actually need to access an element. In this post, TIm Ekl uses a lazy collection together with flatmap to efficiently find a specific type in an array of types.