Skip to content

Instantly share code, notes, and snippets.

@MrMage
Created December 17, 2016 21:41
Show Gist options
  • Save MrMage/74c7920af49ad82ba7fb5549a24047a6 to your computer and use it in GitHub Desktop.
Save MrMage/74c7920af49ad82ba7fb5549a24047a6 to your computer and use it in GitHub Desktop.
public struct NonemptySequence<Element> {
fileprivate let _storage: [Element]
public init(first: Element, rest: [Element]) {
_storage = [first] + rest
}
}
extension NonemptySequence: Sequence {
// call through to _storage here
}
extension NonemptySequence where Element: Equatable {
public static func ==(A: NonemptySequence, B: NonemptySequence) -> Bool {
return A._storage == B._storage
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment