# Can a generic item depend on a generic template instead of a generic type?

**URL:** <https://forums.swift.org/t/can-a-generic-item-depend-on-a-generic-template-instead-of-a-generic-type/86684>\
**Category:** Using Swift\
**Tags:** generics, extensions, extension\
**Created:** [May 12, 2026, 9:05pm UTC](https://forums.swift.org/t/can-a-generic-item-depend-on-a-generic-template-instead-of-a-generic-type/86684 "2026-05-12T21:05:21Z")\
**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:** [May 12, 2026, 9:05pm UTC](https://forums.swift.org/t/can-a-generic-item-depend-on-a-generic-template-instead-of-a-generic-type/86684/1 "2026-05-12T21:05:21Z")

</div>

Here's what I want to do:

```swift
extension Sequence<T> where Element == SortedSetElement<T> {
  //...
}

```

I get an error that `T` is not in scope.

The first generic depends on a specific instantiation of the second, but the first generic's parameters depend on the second generic's parameters.

---

<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:** [May 12, 2026, 9:32pm UTC](https://forums.swift.org/t/can-a-generic-item-depend-on-a-generic-template-instead-of-a-generic-type/86684/2 "2026-05-12T21:32:57Z")

</div>

I used an extension to switch the order the dependencies are specified:

```swift
extension SortedSetElement {
  struct MySequence<Base: Sequence> where Base.Element == SortedSetElement {
    //...
  }
}

```

(You can't use "`Self`" at the end of the second line, because it's an alias for "`MySequence`" instead by that point.)

---

<div class="post-metadata">

**Author:** ![jrose](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jrose/32/408_2.png) [@jrose](https://forums.swift.org/u/jrose)\
**Post date:** [May 12, 2026, 10:51pm UTC](https://forums.swift.org/t/can-a-generic-item-depend-on-a-generic-template-instead-of-a-generic-type/86684/3 "2026-05-12T22:51:38Z")

</div>

You can't yet do it at the extension level, but if the only things you're adding are methods, initializers, or subscripts, you can do it by moving the `where` clause to the member instead:

```swift
extension Sequence {
  func doSomethingWithSortedSets<T>()
  where Element == SortedSetElement<T> {
    // ...
  }
}

```
