Last active
December 15, 2015 15:49
-
-
Save mesagie/5284185 to your computer and use it in GitHub Desktop.
Fluent indirect comparison
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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