Generator

replpp.shaded.geny.Generator
See theGenerator companion object
trait Generator[+A]

Provides the geny.Gen data type, A Generator of elements of type A.

Generator is basically the inverse of a scala.Iterator: instead of the core functionality being the pull-based hasNext and next: T methods, the core is based around the push-based generate method. generate is basically an extra-customizable version of foreach, which allows the person calling it to provide basic control-flow instructions to the upstream Gens.

Unlike a scala.Iterator, subclasses of Generator can guarantee any clean up logic is performed by placing it after the generate call is made.

Transformations on a Generator are lazy: calling methods like filter or map do not evaluate the entire Gen, but instead construct a new Gen that delegates to the original. The only methods that evaluate the Generator are the "Action" methods like generate/foreach/find, or the "Conversion" methods like toArray or similar.

generate takes a function returning Gen.Action rather that Unit. This allows a downstream Gen to provide basic control commands to the upstream Gens: i.e. Generator.End to cease enumeration of the upstream Gen. This allows it to avoid traversing and processing elements that the downstream Gen doesn't want/need to see anyway.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

def generate(handleItem: A => Action): Action

The core abstract method that defines the Generator trait. It is essentially the same as .foreach, but with additional configurability.

The core abstract method that defines the Generator trait. It is essentially the same as .foreach, but with additional configurability.

Value parameters

handleItem

How to handle a single item: performs any desired side effects, and returns a Generator.Action that determines how to continue the enumeration.

Attributes

Returns

an integer stating how many skipped elements from the startingSkipped input remain to be skipped after this generate call has completed.

Concrete methods

def ++[B >: A](other: Generator[B]): Generator[B]
def collect[B](func: PartialFunction[A, B]): Generator[B]
def collectFirst[B](func: PartialFunction[A, B]): Option[B]
def contains(a: Any): Boolean
def count(f: A => Boolean): Int
def drop(n: Int): Generator[A]
def dropWhile(pred: A => Boolean): Generator[A]
def exists(f: A => Boolean): Boolean
def filter(pred: A => Boolean): Generator[A]
def find(f: A => Boolean): Option[A]
def flatMap[B](func: A => Generator[B]): Generator[B]
def flatten[V](implicit f: A => Generator[V]): Generator[V]
def fold[B](start: B)(f: (B, A) => B): B
def foldLeft[B](start: B)(f: (B, A) => B): B
def forall(f: A => Boolean): Boolean
def foreach(f: A => Unit): Unit
def head: A
def headOption: Option[A]
def map[B](func: A => B): Generator[B]
def max[B >: A](implicit cmp: Ordering[B]): A
def maxBy[B](f: A => B)(implicit cmp: Ordering[B]): A
def min[B >: A](implicit cmp: Ordering[B]): A
def minBy[B](f: A => B)(implicit cmp: Ordering[B]): A
def mkString(start: String, sep: String, end: String): String
def mkString(sep: String): String
def mkString: String
def product[B >: A](implicit num: Numeric[B]): B
def reduce[B >: A](f: (B, A) => B): B
def reduceLeft[B >: A](f: (B, A) => B): B
def slice(start: Int, end: Int): Generator[A]
def sum[B >: A](implicit num: Numeric[B]): B
def take(n: Int): Generator[A]
def takeWhile(pred: A => Boolean): Generator[A]
def toArray[B >: A : ClassTag]: Array[B]
def toBuffer[B >: A]: Buffer[B]
def toList: List[A]
def toSeq: Seq[A]
def toSet[B >: A]: Set[B]
def toVector: Vector[A]
def withFilter(pred: A => Boolean): Generator[A]
def zip[B](other: Iterable[B]): Generator[(A, B)]
def zipWithIndex: Generator[(A, Int)]