Hello.
In my application I have the following code snippet:
Sorted lazy collection
let array = [1, 10, 5, 6, 20, 45, 3, 12, 14, 21, 6, 7]
var i = 0
let result = array.lazy.sorted { a, b -> Bool in
print("predicate " + String(i))
i += 1
return a < b
}.first
print(result ?? 0)
Predicate that I pass to sorted(by:) is calling 35 times. However I expect that it will be called less times, because I use a lazy collection and I need only the first item of sorted result. As I know sorted(by:) uses the Introsort algorithm, that's why I guess it is possible to use call-by-need for it.