Thanks to this thread, I followed this link from Akos Krivach's comment.
The code in the solution is as follow:
implicit def enhanceWithContainsDuplicates[T](s:List[T]) = new {
def containsDuplicates = (s.distinct.size != s.size)
}
assert(List(1,2,2,3).containsDuplicates)
assert(!List("a","b","c").containsDuplicates)
I have never seen that new
keyword used in this context.
Anyone can enlighten me on how it works? Is there a name for this pattern?
Cheers