I saw this “SQL joins as Venn diagrams” image on this Twitter page. To give attribution to the original author, it appears to have been created by C.L. Moffatt and documented in this Visual Representation of SQL Joins article. However, this article makes the case that Venn diagrams are not an accurate description of SQL joins.
A cool thing about Scala sets -- and some other Scala collections -- is that you can easily determine the union, intersection, and difference between two sets. The following examples demonstrate how the methods work. First, we create two sets that have a slight overlap:
scala> val low = 1 to 5 toSet low: scala.collection.immutable.Set[Int] = Set(5, 1, 2, 3, 4) scala> val medium = (3 to 7).toSet medium: scala.collection.immutable.Set[Int] = Set(5, 6, 7, 3, 4)
Now we exercise the methods. First, the