Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Beginning Swift

You're reading from   Beginning Swift Master the fundamentals of programming in Swift 4

Arrow left icon
Product type Paperback
Published in May 2018
Publisher Packt
ISBN-13 9781789534313
Length 202 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Rob Kerr Rob Kerr
Author Profile Icon Rob Kerr
Rob Kerr
Kåre Morstøl Kåre Morstøl
Author Profile Icon Kåre Morstøl
Kåre Morstøl
Arrow right icon
View More author details
Toc

Lazy Operations


All the sequences and methods we have looked at so far this lesson have been eager, which means they perform their operations immediately, and filter, map, and flatMap return their results in arrays. But sometimes, we may want to delay operations until they are needed.

Say you have a very large array, and you want to first use map and then perform other operations. If done eagerly, map will create a new array with the same number of elements as the original one to store its results. But if we do it lazily, map will return a LazyMapSequence, which will perform each map operation directly when asked for, without using any intermediate storage.

Infinite sequences must be handled lazily, as they obviously cannot be stored.

Lazy Sequences

A lazy sequence is one that conforms to LazySequenceProtocol. The original sequence itself may or may not work lazily internally, but some further operations on the sequence...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime