Skip to content

Instantly share code, notes, and snippets.

@mesagie
Last active December 15, 2015 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mesagie/5284185 to your computer and use it in GitHub Desktop.
Save mesagie/5284185 to your computer and use it in GitHub Desktop.
Fluent indirect comparison
implicit class pimpTuple[T](val tuple: (T, T)) extends AnyVal {
def haveSame(f: (T => Any)) = f(tuple._1) == f(tuple._2)
}
val (sentence1, sentence2) = ("To be or not to be","That is the question")
// Now we can do
(sentence1, sentence2) haveSame (_ split " " size) // false
// Instead of
sentence1.split(" ").size == sentence2.split(" ").size // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment