IterableFactory

trait IterableFactory[+CC[_]] is a base trait for companion objects for specific collections which provides a number of operations to create a specific collection with the type specified by the CC type constructor; this is sometimes called target-type driven building because the type of the source collection is ignored. Most of the companion objects in the collection library extend this trait, which makes it possible to use them in places where IterableFactory is expected. 

As this is the main abstraction that allows to build a collection from scratch, it is useful to know which methods it supplies. All of them return CC[A]. The following table contains a short summary:

def from[A](source: IterableOnce[A]) Creates a target collection from existing IterableOnce.
def empty[A]: CC[A] An empty collection, often defined as an object.
def apply[A](elems: A*): CC[A] Creates a collection from the elems given as var-arg.
def iterate[A](start: A, len: Int)(f: A => A): CC[A] Fills the collection with values taken from the result of the application of f on start, then on produced values and so on, len number of times.
def range[A : Integral](start: A, end: A, step: A): CC[A] Collection containing increasing integers [start, end-1] with difference between successive numbers of step. There is also a version of this method with default value of step = 1.
def fill[A](n: Int)(elem: => A): CC[A] Fills the collection with n evaluations of elem. There are variations of this function that go up to five dimensions.
def tabulate[A](n: Int)(f: Int => A): CC[A] The same as fill, but using index as an argument for the evaluation. Similarly, there are variations of this function that go up to five dimensions.
def concat[A](xss: Iterable[A]*): CC[A] Concatenates all argument collections into a single collection.
def unfold[A, S](init: S)(f: S => Option[(A, S)]): CC[A] Calls f to produce the element of the collection using and modifying the internal state starting with the init state.

 

Arguably, IterableFactory provides a lot of different possibilities to create a collection of a desired type.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.20.68