Lazy Sequences in Swift • Andy Ibanez

PHOTO EMBED

Sat Sep 10 2022 22:02:19 GMT+0000 (Coordinated Universal Time)

Saved by @kaushalPal0812

struct Character {
  let name: String
}

let characters = ["Elize", "Arietta", "Anise"]

let mappedCharacters = characters.map { Character(name: $0) } // A new collection of 3 elements
let lazyMappedCharacters = characters.lazy.map { Character(name: $0) } // This won't execute any code until you need it.

print(lazyMappedCharacters[2])
content_copyCOPY

https://www.andyibanez.com/posts/lazy-sequences-in-swift/