Tuesday, February 5, 2013

Custom scala set example

which gives :

scala> val a=NamedCustomSet("toto", 1, 2, 3,4)
a: dummy.NamedCustomSet[Int] = NamedCustomSet(toto,1,2,3,4)

scala> val b=NamedCustomSet("tata")
b: dummy.NamedCustomSet[Nothing] = NamedCustomSet(tata)

scala> val c=NamedCustomSet("tutu",10)
c: dummy.NamedCustomSet[Int] = NamedCustomSet(tutu,10)

scala> a++c
res7: dummy.NamedCustomSet[Int] = NamedCustomSet(toto,10,1,2,3,4)

scala> a.map(_ + 1)
res8: dummy.NamedCustomSet[Int] = NamedCustomSet(toto,2,3,4,5)

scala> a++List(50,100)
res9: dummy.NamedCustomSet[Int] = NamedCustomSet(toto,1,2,3,50,4,100)

scala> a.map(_.toString)
res10: dummy.NamedCustomSet[String] = NamedCustomSet(toto,1,2,3,4)

scala> a.reduce(_ + _)
res11: Int = 10

scala> a.max
res12: Int = 4

No comments:

Post a Comment