это пример изучения идентичного списка цветов:
case class Color(n: String, name: String, lightOrDark: String, n2: String)
val k1 = Color("1", "red", "light", "10")
val k2 = Color("1", "blue", "dark", "11")
val k3 = Color("1", "orange", "dark", "11")
val k4 = Color("1", "red", "light", "10")
val k5 = Color("1", "red", "dark", "200")
println(k1.hashCode() == k2.hashCode())
println(k1.hashCode() == k4.hashCode())
val set = mutable.Set.empty[Int]
val colorList = List(k1, k2, k3, k4, k5)
val restResult =
Source
.fromIterator(colorList.iterator _)
.map { color =>
val hashCode = color.hashCode()
val res = !set.contains(hashCode)
set += hashCode
res
}.takeWhile(identity, inclusive = true)
.runWith(Sink.last)
restResult.onComplete {
case Success(value) =>
println(value)
system.terminate()
case Failure(e) =>
e.printStackTrace()
system.terminate()
}
весь источник здесь