trait _read

Stream Iteration Interface

The methods below are special. Unlike most others, they can be called on the same stream many times.

class java.lang.Object
trait scala.Matchable
class Any
trait _use
object ~


inline def read[A]: A

Next element

Next element

Delivers next stream element

 val s : ~[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 read_? in most cases

inline def read_~[A](inline cnt: Int): ~[A] & Able.Size

Read many elements

Read many elements

Immediatelly removes given number of elements from current stream and returns them as a new stream

 val s : ~[Int] = 1 <> 12

 s.read_~(3).tp  // Prints ~(1, 2, 3)
 s.read_~(4).tp  // Prints ~(4, 5, 6, 7)
 s.read_~(7).tp  // Prints ~(8, 9, 10, 11, 12)
 s.read_~(8).tp  // Prints ~()

Note: If requested number of elements is not available, the number returned is less (0 if empty)

inline def read_?[A]: Opt[A]

Next optional element

Next optional element

Delivers next stream element or void option if stream is empty

 val s : ~[Char] = 'A' <> 'C'

 s.read_?.tp  // Prints Opt(A)
 s.read_?.tp  // Prints Opt(B)
 s.read_?.tp  // Prints Opt(C)
 s.read_?.tp  // Prints Opt(\/)