Ufuk Canlı
Ufuk's Blog

Follow

Ufuk's Blog

Follow
TIL: Lazy sequences

Photo by Julian Hochgesang on Unsplash

TIL: Lazy sequences

Ufuk Canlı's photo
Ufuk Canlı
·Feb 22, 2023·

1 min read

I've been thinking to myself that gotta get back to writing somehow. It is a time-consuming job to write a long blog post both for the reader and the writer. I see now why Twitter is so popular among the people like us (developers, designers etc.). I'd like to share some quick tips I learn here in this series.

If you are using .map, .filter, and .reduce methods a lot, you will enjoy this tip. When you are iterating over a large amount of array of items using the lazy keyword will help you boost the performance.

let lazyFilterSequence = Array(0...100).lazy.filter { $0 % 2 == 0 }
let lazyFilteredArray = Array(lazyFilterSequence)