_read
Stream Iteration Interface
The methods below are special. Unlike most others, they can be called on the same stream many times.
- Source
- _read.scala
Def
Next element
Next element
Delivers next stream element
val s : Stream[Char] = 'A' <> 'Z'
s.read.tp // Prints A
s.read.tp // Prints B
s.read.tp // Prints C
Note: If stream is empty, read will fail. So, use a safer readOpt in most cases
- Source
- _read.scala
Next optional element
Next optional element
Delivers next stream element or void option if stream is empty
val s : Stream[Char] = 'A' <> 'C'
s.readOpt.tp // Prints Opt(A)
s.readOpt.tp // Prints Opt(B)
s.readOpt.tp // Prints Opt(C)
s.readOpt.tp // Prints Opt(VOID)
- Source
- _read.scala
Read many elements
Read many elements
Immediatelly removes given number of elements from current stream and returns them as a new stream
val s : Stream[Int] = 1 <> 12
s.readStream(3).tp // Prints Stream(1, 2, 3)
s.readStream(4).tp // Prints Stream(4, 5, 6, 7)
s.readStream(7).tp // Prints Stream(8, 9, 10, 11, 12)
s.readStream(8).tp // Prints Stream()
Note: If requested number of elements is not available, the number returned is less (0 if empty)
- Source
- _read.scala