In Scala ListSet, takeWhile() method is utilized to find the elements from the list as long as the stated condition is satisfied.
Method Definition: def takeWhile(p: (A) => Boolean): ListSet[A] Return Type: It returns the elements from the list as long as the stated condition is satisfied.
Example 1:
Scala
import scala.collection.immutable. _
object GfG
{
def main(args : Array[String])
{
val m 1 = ListSet( 1 , 2 , 3 , 4 , 5 , 7 )
val result = m 1 .takeWhile( _ > 3 )
println(result)
}
}
|
Example 2:
Scala
import scala.collection.immutable. _
object GfG
{
def main(args : Array[String])
{
val m 1 = ListSet( 1 , 2 , 3 , 4 , 5 , 7 )
val result = m 1 .takeWhile( _ > 7 )
println(result)
}
}
|