# Are primary associated types supposed to be transitive?

**URL:** <https://forums.swift.org/t/are-primary-associated-types-supposed-to-be-transitive/72985>\
**Category:** Using Swift\
**Tags:** associatedtype, sequence, lazysequence\
**Created:** [July 6, 2024, 5:19pm UTC](https://forums.swift.org/t/are-primary-associated-types-supposed-to-be-transitive/72985 "2024-07-06T17:19:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CTMacUser](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ctmacuser/32/1802_2.png) [@CTMacUser](https://forums.swift.org/u/CTMacUser)\
**Post date:** [July 6, 2024, 5:19pm UTC](https://forums.swift.org/t/are-primary-associated-types-supposed-to-be-transitive/72985/1 "2024-07-06T17:19:15Z")

</div>

Have a function that returns "`some Sequence<MyElement>`." The sequence type is also a lazy sequence, but "`some LazySequenceProtocol<MyElement>`" doesn't work. So:

- Transitivity is supposed to work, but there's a (major) problem with the compiler.
- Transitivity isn't supported, and the Swift team forgot to tag a primary associative type for `LazySequenceProtocol`.
- The Swift team deliberately doesn't want to give `LazySequenceProtocol` a primary type.

I can see transitivity not (initially?) being supported a valid decision, so I'm guessing the answer is #2. Unless someone can supply a reason why it's actually #3.

---

<div class="post-metadata">

**Author:** ![Quedlinbug](https://avatars.discourse-cdn.com/v4/letter/q/77aa72/32.png) [@Quedlinbug](https://forums.swift.org/u/Quedlinbug)\
**Post date:** [July 6, 2024, 5:56pm UTC](https://forums.swift.org/t/are-primary-associated-types-supposed-to-be-transitive/72985/2 "2024-07-06T17:56:10Z")

</div>

I don't know the answer. I've just used composition to get around it so far.

```swift
some Sequence<MyElement> & LazySequenceProtocol

```

---

<div class="post-metadata">

**Author:** ![xwu](https://avatars.discourse-cdn.com/v4/letter/x/b487fb/32.png) [@xwu](https://forums.swift.org/u/xwu)\
**Post date:** [July 6, 2024, 6:33pm UTC](https://forums.swift.org/t/are-primary-associated-types-supposed-to-be-transitive/72985/3 "2024-07-06T18:33:39Z")

</div>

> [@CTMacUser](#):
>
> Unless someone can supply a reason why it's actually #3.

It's actually #3, because there was doubt about the right primary associated type, which would notably _not_ have been `Element`.

> [@\[Pitch\] Primary Associated Types in the Standard Library](https://forums.swift.org/t/pitch-primary-associated-types-in-the-standard-library/56426/26):
>
> > [@\[Pitch\] Primary Associated Types in the Standard Library](https://forums.swift.org/t/pitch-primary-associated-types-in-the-standard-library/56426/1):
> >
> > `LazySequenceProtocol` and `LazyCollectionProtocol` use `Elements` as their primary associated type, not `Element` . The idea here is that if we spell out `LazyCollectionProtocol` , we probably want to also say something about the wrapped collection, not just its element type -- for example, by constraining it to random access collections using `some LazyCollectionProtocol<some RandomAccessCollection<String>>` .
> 
> Personally, I'd rather we not add any primary associated types to `LazySequenceProtocol` and `LazyCollectionProtocol`. They aren't likely to be used often, and it feels odd to have them be based on `Elements` rather than `Element` like the other sequence/collection protocols. We could always add them later if compelling use cases show up in sufficient quantity.

> [@\[Pitch\] Primary Associated Types in the Standard Library](https://forums.swift.org/t/pitch-primary-associated-types-in-the-standard-library/56426/43):
>
> The document no longer proposes primary associated types for `LazySequenceProtocol` and `LazyCollectionProtocol`. I still think `Elements` is the right choice for these, but this is mostly based on speculation rather than actual use cases. I would like to add these back, but I'd love to see some actual example cases to confirm/reject this choice.
