|
Scala example source code file (withIndex.scala)
The Scala withIndex.scala source codeobject Test { def main(args: Array[String]) = { val ary: Array[String] = Array("a", "b", "c") val lst: List[String] = List("a", "b", "c") val itr: Iterator[String] = lst.iterator val str: Stream[String] = lst.iterator.toStream Console.println(ary.zipWithIndex.toList) Console.println(lst.zipWithIndex.toList) Console.println(itr.zipWithIndex.toList) Console.println(str.zipWithIndex.toList) assert { ary.zipWithIndex match { case _: Array[Pair[_,_]] => true case _ => false } } val emptyArray = new Array[String](0) val emptyList: List[String] = Nil val emptyIterator = emptyList.iterator val emptyStream: Stream[String] = Stream.empty Console.println(emptyArray.zipWithIndex.toList) Console.println(emptyList.zipWithIndex.toList) Console.println(emptyIterator.zipWithIndex.toList) Console.println(emptyStream.zipWithIndex.toList) } } Other Scala examples (source code examples)Here is a short list of links related to this Scala withIndex.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.