In Scala, scala.collection.mutable implements Stack data structure. The :\ method applies a binary operator to a start value and all elements of this traversable or iterator, going right to left.
Method Definition – def :\[B](z: B)(op: (A, B) ? B): B
Returns – the result of inserting op between consecutive elements of this traversable or iterator.
Example #1:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val st 1 = Stack( 1 , 2 , 3 )
val result 1 = (st 1 : \ 16 )( _ + _ )
val result 2 = (st 1 : \ 16 )( _ - _ )
print(result 1 )
print( "\n" )
print(result 2 )
}
}
|
Example #2:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val q 2 = List( 11 , 12 , 13 , 14 , 15 )
val result = (q 2 : \ 6 )( _ + _ )
print(result)
}
}
|