Skip to content

Instantly share code, notes, and snippets.

@salanki
Created March 20, 2011 05:42
Show Gist options
  • Save salanki/878126 to your computer and use it in GitHub Desktop.
Save salanki/878126 to your computer and use it in GitHub Desktop.
def union[A](a: Set[A], b: Set[A]) {
var c = b
for(item <- a) {
c += item
}
c
}
OR:
def union[A](a: Set[A], b: Set[A]){
var c = b
a.foreach {
c += _
}
c
}
OR:
def union[A](a: Set[A], b: Set[A]){
b.foldLeft(a)((in, item) => in + item)
}
OR:
def union[A](a: Set[A], b: Set[A]){
b.foldLeft(a)(_ + _)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment