# Is a set a sequence?

**URL:** <https://forums.swift.org/t/is-a-set-a-sequence/11715>\
**Category:** Discussion\
**Created:** [April 6, 2018, 7:37am UTC](https://forums.swift.org/t/is-a-set-a-sequence/11715 "2018-04-06T07:37:56Z")\
**Posts on this page:** 1\
**Showing post:** 33

<div class="post-metadata">

**Author:** ![jawbroken](https://avatars.discourse-cdn.com/v4/letter/j/cc9497/32.png) [@jawbroken](https://forums.swift.org/u/jawbroken)\
**Post date:** [April 8, 2018, 11:46pm UTC](https://forums.swift.org/t/is-a-set-a-sequence/11715/33 "2018-04-08T23:46:52Z")

</div>

> [@Tino](#):
>
> I’m not in the position to complain about satire - but I’d prefer it to be funny ;-)  
> The confusion with elementsEqual is a real world problem, and there are several other examples that illustrate that the status quo is far from perfect.

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.

> [@Tino](#):
>
> The for loop is a vehicle to process the contents of a collection, and you can use it for tasks that depend on a certain order, as well as to perform operations where you just need to do something with each element.

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

```swift
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.

---

_[View the full topic](https://forums.swift.org/t/is-a-set-a-sequence/11715)._
