Skip to content

Instantly share code, notes, and snippets.

@nicl
Last active December 17, 2015 13:49
Show Gist options
  • Save nicl/5620254 to your computer and use it in GitHub Desktop.
Save nicl/5620254 to your computer and use it in GitHub Desktop.
Scala Universal Set
class UniversalSet[A] extends Set[A] {
def contains(key: A) = true
def iterator = throw new UnsupportedOperationException()
def +(elem: A) = this
def -(elem: A) = throw new UnsupportedOperationException()
override def toString: String = "UniversalSet"
}
@nicl
Copy link
Author

nicl commented May 21, 2013

This is a bare minimum implementation. There are likely several other methods/traits I need to implement to make this usable, for example isEmpty(). In fact, any of the mixed-in methods that rely on iterator will error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment