Preview is an extension of stream with preview capabilities
It allows to pre-load and inspect elements before they are read from the stream
val s : Stream[Int] = 1 <> 10
val ps : Stream.Preview[Int] = s.enablePreview
ps.preview.tp // Prints 1
ps.previewStream(5).tp // Prints Stream(1, 2, 3, 4, 5)
ps.previewStream(3).tp // Prints Stream(1, 2, 3)
(ps.previewSize > 12).tp // Prints false
ps.tp // Prints Stream(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
ps.tp // Prints Stream()
- Source
- __.scala
Def
Preview next element
Preview next element
Returns element, waiting in the pipeline to be next
Operation will fail if stream is empty
- Source
- __.scala
Preview next optional element
Preview next optional element
Optionally returns element, waiting in the pipeline to be next or empty option if there is none
- Source
- __.scala
Lazy size interface
Lazy size interface
Returns a lazily evaluated size object, which preloads just enough elements to answer sizing requests
def s: Stream[String] = ???
def p: Stream.Preview[String] = s.preview
p.previewSize >= 10 // This will pre-load no more than 10 elements
p.previewSize < 100 // This will pre-load no more than 100 elements
- Source
- __.scala
Preview multiple elements
Preview multiple elements
Returns a Stream of elements waiting in the pipeline to be fetched next
A given count of elements is requested, but returned count can be less (even zero) if not enough is available
- Source
- __.scala
Read next option
Read next option
Optionally returns next element or empty option
If empty option is returned, the stream is considered exhasted and should be discarded
This is the only real method of stream interface, the rest of functionality is provided with extension methods for:
Read many elements with condition
Read many elements with condition
Immediatelly removes all consequtive stream elements which satisfy the given predicate.
The removed elements are returned as a new stream
Non consequtive, but complient elements found later will not be affected.
Note. This operation is only available in Preview interface, because it requires to examine elements before they are read
- Source
- __.scala