Chunk
Strict, finite sequence of values that allows index-based random access of elements.
Chunk
s can be created from a variety of collection types using methods on the Chunk
companion(e.g.,
Chunk.array
, Chunk.seq
, Chunk.vector
).Chunks can be appended via the
chunks -- that is, there's no copying of the source chunks. For example,
returns a
an appended chunk is
has size 1, indexed lookup is
chunk elements to a single array backed chunk. Note
++
method. The returned chunk is a composite of the inputchunks -- that is, there's no copying of the source chunks. For example,
Chunk(1, 2) ++ Chunk(3, 4) ++ Chunk(5, 6)
returns a
Chunk.Queue(Chunk(1, 2), Chunk(3, 4), Chunk(5, 6))
. As a result, indexed based lookup ofan appended chunk is
O(number of underlying chunks)
. In the worse case, where each constituent chunkhas size 1, indexed lookup is
O(size)
. To restore O(1)
lookup, call compact
, which copies all the underlyingchunk elements to a single array backed chunk. Note
compact
requires a ClassTag
of the element type.Alternatively, a collection of chunks can be directly copied to a new array backed chunk via
Chunk.concat(chunks)
. Like compact
, Chunk.concat
requires a ClassTag
for the element type.Various subtypes of
-
-
-
Chunk
are exposed for efficiency reasons:-
Chunk.Singleton
-
Chunk.ArraySlice
-
Chunk.Queue
In particular, calling
access to the underlying backing array, along with an offset and length, referring to a slice
of that array.
.toArraySlice
on a chunk returns a Chunk.ArraySlice
, which providesaccess to the underlying backing array, along with an offset and length, referring to a slice
of that array.
- Companion
- object
Value members
Methods
Returns a chunk which consists of the elements of this chunk and the elements of
the supplied chunk. This operation is amortized O(1).
the supplied chunk. This operation is amortized O(1).
Returns the first element for which the predicate returns true or
None
if no elements satisfy the predicate.Creates an iterator that iterates the elements of this chunk. The returned iterator is not thread safe.
Returns the index of the first element which passes the specified predicate (i.e.,
or
p(i) == true
)or
None
if no elements pass the predicate.Maps the supplied stateful function over each element, outputting the final state and the accumulated outputs.
The first invocation of
the output state of the previous invocation.
The first invocation of
f
uses init
as the input state value. Each successive invocation usesthe output state of the previous invocation.
Creates an iterator that iterates the elements of this chunk in reverse order. The returned iterator is not thread safe.
Like
the last element of the accumulated chunk.
scanLeft
except the final element is emitted as a standalone value instead of asthe last element of the accumulated chunk.
Equivalent to
val b = a.scanLeft(z)(f); val (c, carry) = b.splitAt(b.size - 1)
.Check to see if this starts with the items in the given seq
should be the same as take(seq.size).toChunk == Chunk.seq(seq).
should be the same as take(seq.size).toChunk == Chunk.seq(seq).
def traverseFilter[F <: ([_$9] =>> Any), O2](f: O => F[Option[O2]])(F: Applicative[F]): F[Chunk[O2]]