lazy.filter.map.prefix: how many times is map called?
Task
var calls = 0
let result = (1...9).lazy
.filter { $0 % 2 == 1 }
.map { value -> Int in
calls += 1
return value * value
}
.prefix(3)
print(Array(result), calls)
What gets printed? And without .lazy?
The rest of this answer, with code and interview follow-ups, is in the DevPrep app.
Read the full answer in DevPrep