[use case] Returns a new collection containing the elements from the left hand operand followed by the elements from the right hand operand.
Returns a new collection containing the elements from the left hand operand followed by the elements from the right hand operand. The element type of the collection is the most specific superclass encompassing the element types of the two operands.
Example:
scala> val a = NonEmpty(1) a: NonEmpty[Int] = List(1) scala> val b = NonEmpty(2) b: NonEmpty[Int] = List(2) scala> val c = a ++ b c: NonEmpty[Int] = List(1, 2) scala> val d = NonEmpty('a') d: NonEmpty[Char] = List(a) scala> val e = c ++ d e: NonEmpty[AnyVal] = List(1, 2, a)
the element type of the returned collection.
the traversable to append.
a new collection which contains all elements of this collection
followed by all elements of that
.
Partitions this collection into a map of collections according to some discriminator function.
Partitions this collection into a map of collections according to some discriminator function.
the type of keys returned by the discriminator function.
the discriminator function.
A map from keys to collections such that the following invariant holds:
(xs groupBy f)(k) = xs filter (x => f(x) == k)
That is, every key k
is bound to a collection of those elements x
for which f(x)
equals k
.
Partitions elements in fixed size collections.
Partitions elements in fixed size collections.
the number of elements per group
An iterator producing collections of size size
, except the
last will be less than size size
if the elements don't
divide evenly.
[use case] Builds a new collection by applying a function to all elements of this collection.
Builds a new collection by applying a function to all elements of this collection.
the element type of the returned collection.
the function to apply to each element.
a new collection resulting from applying the given function
f
to each element of this collection and collecting
the results.
Computes a prefix scan of the elements of the collection.
Computes a prefix scan of the elements of the collection.
Note: The neutral element z
may be applied more than once.
element type of the resulting collection
type of the resulting collection
neutral element for the operator op
the associative operator for the scan
combiner factory which provides a combiner
a new collection containing the prefix scan of the elements in this collection
Produces a collection containing cumulative results of applying the operator going left to right.
Produces a collection containing cumulative results of applying the operator going left to right.
Note: will not terminate for infinite-sized collections.
Note: might return different results for different runs, unless the underlying collection type is ordered.
the type of the elements in the resulting collection
the actual type of the resulting collection
the initial value
the binary operator applied to the intermediate result and the element
an implicit value of class CanBuildFrom
which determines
the result class That
from the current representation type
Repr
and and the new element type B
.
collection with intermediate results
Produces a collection containing cumulative results of applying the operator going right to left.
Produces a collection containing cumulative results of applying the operator going right to left. The head of the collection is the last cumulative result.
Note: will not terminate for infinite-sized collections.
Note: might return different results for different runs, unless the underlying collection type is ordered.
Example:
NonEmpty(1, 2, 3, 4).scanRight(0)(_ + _) == NonEmpty(10, 9, 7, 4, 0)
the type of the elements in the resulting collection
the actual type of the resulting collection
the initial value
the binary operator applied to the intermediate result and the element
an implicit value of class CanBuildFrom
which determines
the result class That
from the current representation type
Repr
and and the new element type B
.
collection with intermediate results
(Changed in version 2.9.0) transpose
throws an IllegalArgumentException
if collections are not uniformly sized.
Converts this collection of pairs into two collections of the first and second half of each pair.
Converts this collection of pairs into two collections of the first and second half of each pair.
val xs = NonEmpty( (1, "one"), (2, "two"), (3, "three")).unzip // xs == (NonEmpty(1, 2, 3), // NonEmpty(one, two, three))
the type of the first half of the element pairs
the type of the second half of the element pairs
an implicit conversion which asserts that the element type of this collection is a pair.
a pair of collections, containing the first, respectively second half of each element pair of this collection.
Converts this collection of triples into three collections of the first, second, and third element of each triple.
Converts this collection of triples into three collections of the first, second, and third element of each triple.
val xs = NonEmpty( (1, "one", '1'), (2, "two", '2'), (3, "three", '3')).unzip3 // xs == (NonEmpty(1, 2, 3), // NonEmpty(one, two, three), // NonEmpty(1, 2, 3))
the type of the first member of the element triples
the type of the second member of the element triples
the type of the third member of the element triples
an implicit conversion which asserts that the element type of this collection is a triple.
a triple of collections, containing the first, second, respectively third member of each element triple of this collection.
[use case] Returns a collection formed from this collection and another iterable collection by combining corresponding elements in pairs.
Returns a collection formed from this collection and another iterable collection by combining corresponding elements in pairs. If one of the two collections is shorter than the other, placeholder elements are used to extend the shorter collection to the length of the longer.
Note: might return different results for different runs, unless the underlying collection type is ordered.
the type of the second half of the returned pairs
the iterable providing the second half of each result pair
the element to be used to fill up the result if this
collection is shorter than that
.
the element to be used to fill up the result if that
is shorter than this collection.
a new collection containing pairs consisting of
corresponding elements of this collection and
that
. The length of the returned collection
is the maximum of the lengths of this collection
and that
. If this collection is shorter than
that
, thisElem
values are used to pad the
result. If that
is shorter than this collection,
thatElem
values are used to pad the result.
[use case] Zips this collection with its indices.
Zips this collection with its indices.
Note: might return different results for different runs, unless the underlying collection type is ordered.
a new collection containing pairs consisting of all elements
of this collection paired with their index. Indices
start at 0
.
NonEmpty("a", "b", "c").zipWithIndex = NonEmpty(("a", 0), ("b", 1), ("c", 2))
(nonEmpty: Iterable[A]).++(that)(bf)
(nonEmpty: Iterable[A]).groupBy(f)
(nonEmpty: Iterable[A]).grouped(size)
(nonEmpty: Iterable[A]).map(f)(bf)
(nonEmpty: Iterable[A]).scan(z)(op)(cbf)
(nonEmpty: Iterable[A]).scanLeft(z)(op)(bf)
(nonEmpty: Iterable[A]).scanRight(z)(op)(bf)
(Changed in version 2.9.0) The behavior of scanRight
has changed. The previous behavior can be reproduced with scanRight.reverse.
(nonEmpty: Iterable[A]).toString()
(nonEmpty: Iterable[A]).unzip(asPair)
(nonEmpty: Iterable[A]).unzip3(asTriple)
(nonEmpty: Iterable[A]).zipAll(that, thisElem, thatElem)(bf)
(nonEmpty: Iterable[A]).zipWithIndex(bf)
A value class for non-empty iterable collections.
It is intended to be used as a parameter type to restrict a collection value to be non-empty. This restriction is guaranteed statically, i.e., it is not possible to pass an empty collection as a parameter of type
NonEmpty[]
.The static safety is guaranteed by three reasons:
NonEmpty[]
other than by factory methods provided by singleton objectNonEmpty
Iterable[A]
toOption[NonEmpty[A]]
where an empty value will be NoneNonEmpty.apply
, which takes at least one argumentA value of type
NonEmpty[A]
can be used as aIterable[A]
by an implicit conversion fromNonEmpty[A]
toIterable[A]
. It also has some collection methods that preserve non-emptiness.