Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumSwiftgenerics and constraintsSingle-choice MCQ

Same-type constraints can pin two associated types together. Why does this extension compile and let you compare across two different `Sequence` types?

extension Sequence { func startsWith<Other: Sequence>(_ other: Other) -> Bool where Other.Element == Element, Element: Equatable { var it = makeIterator() for o in other { guard let s = it.next(), s == o else { return false } } return true } }