Pack

abstract class Pack[A] extends Idx[A]

Value Pack

Pack is the most ubiquitous immutable collection, like List in Scala

Unlike List, Pack is mostly backed by an Array and can be specialized. It usually has smaller memory footprint and in most cases is faster to manipulate data.

Source
__.scala
trait Idx[Pack.A]
trait Collection[Pack.A]
trait Able.Size
trait Able.Stream[Pack.A]
class java.lang.Object
trait scala.Matchable
class Any
class Boolean.G.Pack[Boolean.G.Pack.A]
class Byte.G.Pack[Byte.G.Pack.A]
class Char.G.Pack[Char.G.Pack.A]
class Double.G.Pack[Double.G.Pack.A]
class Float.G.Pack[Float.G.Pack.A]
class Int.G.Pack[Int.G.Pack.A]
class Long.G.Pack[Long.G.Pack.A]
class Short.G.Pack[Short.G.Pack.A]

Def

@targetName("join")
inline def +(v: A): this.type

Alias for join

Alias for join

Creates a new Pack with given value appended to the end of current Pack

Source
__.scala
@targetName("joinAll")
inline def ++(v: Stream[A]): this.type

Alias for joinAll

Alias for joinAll

Creates a new Pack with given stream values appended to the end of current Pack

Source
__.scala
@targetName("joinAllAt")
inline def ++@(i: Int, v: Stream[A]): this.type

Alias for joinAllAt

Alias for joinAllAt

Creates a new Pack with given stream values inserted into current Pack at given position

Source
__.scala
@targetName("join")
inline def +@(i: Int, v: A): this.type

Alias for joinAt

Alias for joinAt

Creates a new Pack with given value inserted into current Pack at given position

Source
__.scala
def apply(i: Int): A

Returns element at specified position

Returns element at specified position

 val idx: Idx[Char] = ('A' <> 'Z').stream.pack

 idx(1).tp // Prints: B

 idx(4).tp // Prints: E
Inherited from
Idx
Source
__.scala
inline def dropFirst(cnt: Int): this.type

Head reversed filter

Head reversed filter

Creates a new Pack from current Pack, skipping given number of first elements

Source
__.scala
inline def dropLast(cnt: Int): this.type

Tail reversed filter

Tail reversed filter

Creates a new Pack from current Pack, skipping given number of last elements

Source
__.scala
def dropRange(from: Int, size: Int): this.type

Range reversed filter

Range reversed filter

Creates a new Pack from current Pack, skipping elements within given range

Source
__.scala
inline def dropRange(r: Int.Range): this.type

Range reversed filter

Range reversed filter

Creates a new Pack from current Pack, skipping elements within given range

Source
__.scala
inline def foreach[U](f: A => U): Unit

Process all elements

Process all elements

Applies given function to each Pack element.

This method is more eficient than Stream foreach.

Source
__.scala
def join(v: A): this.type

Join value

Join value

Creates a new Pack with given value appended to the end of current Pack

Source
__.scala
def joinAll(v: Stream[A]): this.type

Join stream

Join stream

Creates a new Pack with given stream values appended to the end of current Pack

Source
__.scala
def joinAllAt(i: Int, v: Stream[A]): this.type

Join stream at position

Join stream at position

Creates a new Pack with given stream values inserted into current Pack at given position

Source
__.scala
def joinAt(i: Int, v: A): this.type

Join value at position

Join value at position

Creates a new Pack with given value inserted into current Pack at given position

Source
__.scala

Optimize storage

Optimize storage

Returns this.type

Pack is mostly backed by Array. When created from an unknown size stream, Array within pack can end up with larger capacity than required. Because most Packs are short lived, it is wastfull to copy by default this potentially big array to proper size, but operation "pack" on "Pack" type does exactly this on request.

So, when assigning type Pack to a longer term variable, it might be usefull to "double pack" if memory is a concern

val pack = (1 <> 1_000_000).stream.drop(_ % 100 == 0).pack.pack

Note. pack can be called multiple times, but will do anything only if type Pack is not compacted

Source
__.scala
inline def raw(using sp: Specialized.Primitive[A]): s.Pack

Specialize

Specialize

This operation will not compile for reference types

Returns specialized pack for undelying primitive type

Note: If this instance is already specialized, it is returned as is

Source
__.scala
def size: Int
Inherited from
Idx
Source
__.scala
def stream: Stream[A]

Returns a Stream of all elements

Returns a Stream of all elements

The element order is same as in the Idx itself

  val l: Idx[Char] = ('a' <> 'g').stream.pack

  l.stream.tp  // Prints Stream(a, b, c, d, e, f, g)
Inherited from
Idx
Source
__.scala
inline def takeFirst(cnt: Int): this.type

Head filter

Head filter

Creates a new Pack from current Pack, taking only given number of first elements

Source
__.scala
inline def takeLast(cnt: Int): this.type

Tail filter

Tail filter

Creates a new Pack from current Pack, taking only given number of last elements

Source
__.scala
def takeRange(from: Int, size: Int): this.type

Range filter

Range filter

Creates a new Pack from current Pack, taking only elements within given range

Source
__.scala
inline def takeRange(r: Int.Range): this.type

Range filter

Range filter

Creates a new Pack from current Pack, taking only elements within given range

Source
__.scala
def toBuffer: Buffer[A]

Make Buffer

Make Buffer

Creates a Buffer collection filled with Pack elements

Both Buffer and Pack are mostly Array based, so the convertions between them are very efficient

Source
__.scala