Kind of rude, but it's not satirical, it's just an outline of the thought process that led to my conclusions. elementsEqual
is indeed a problem, mostly because it takes two Sequence
s and was an attractive nuisance before things were made Equatable
, but that is already being discussed in its own thread so I presume this thread is about the remaining APIs that expose order. The other handful of methods are perhaps not particularly useful in a lot of situations, but I am not convinced they are particularly harmful.
Sure, but equally something like prefix
could be used to get the first n elements of a collection that I know is in a given order, as in your marathon example, or to get an arbitrary n elements, perhaps because you have some efficient method of processing data in fixed sized chunks.
Your marathon example could have been reasonably written as
func printPodium(of marathon: Marathon) {
var place = 1
for contestant in marathon.succesfulContestants {
guard place <= 3 else { break }
print("Contestant: \(contestant.0) (\(contestant.1 / 3600))")
place += 1
}
}
which exhibits exactly the same issue as your prefix
code. So why is prefix
a problem but not for-in
? You seem to have a strong opinion about which operations that expose an order are harmful and which ones aren't, but I don't understand the basis for those opinions.