|
Scala example source code file (iterables.scala)
The Scala iterables.scala source codeobject Test extends App { class Test(n: Int) extends Iterable[Int] { private var i = 0 def iterator = new Iterator[Int] { def hasNext = i < n def next = if (hasNext) { val v = i; i += 1; v } else throw new IndexOutOfBoundsException("empty iterator") } } { val x = new Test(10) println(x.isEmpty) println(x.mkString(",")) } { val x = new Test(10) println(x.filter(_ > 4).mkString(",")) } { val x = new Test(10) val y = x.partition(_ % 2 == 0) println(y._1.mkString(",")) println(y._2.mkString(",")) } } Other Scala examples (source code examples)Here is a short list of links related to this Scala iterables.scala source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.