~~.Preview

trait Preview[A] extends ~[A]

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  : ~[Int]          = 1 <> 10
val ps : ~~.Preview[Int] = s.enablePreview

ps.preview.tp            // Prints  1

ps.preview_~(5).tp       // Prints  ~(1, 2, 3, 4, 5)

ps.preview_~(3).tp       // Prints  ~(1, 2, 3)

(ps.previewSize > 12).tp // Prints false

ps.tp                    // Prints ~(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
ps.tp                    // Prints ~()
Source
__.scala
trait ~[A]
class java.lang.Object
trait scala.Matchable
class Any

Def

def preview: A

Preview next element

Preview next element

Returns element, waiting in the pipeline to be next

Operation will fail if stream is empty

Source
__.scala
@scala.annotation.targetName("preview_Stream")
def preview_~(cnt: Int): ~[A] & Able.Size

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
@scala.annotation.targetName("preview_Opt")
def preview_?: Opt[A]

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 : ~[String] = ???

def p : ~~.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
@scala.annotation.targetName("read_Opt")
def read_?: Opt[A]

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:

Inherited from
Stream
Source
__.scala
@scala.annotation.targetName("readWhile_Stream")
def readWhile_~(f: A => Boolean): ~[A] & Able.Size

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