Copying operations copyToBuffer and copyToArray. As their names imply, these copy collection elements to a buffer or array, respectively.
Size operations isEmpty, nonEmpty, size, and hasDefiniteSize. Collections that are traversable can be finite or infinite. An example of an infinite traversable collection is the stream of natural numbers
Stream.from(0). The method hasDefiniteSize indicates whether a collection is possibly infinite. If hasDefiniteSize returns true, the collection is certainly finite. If it returns false, the collection might be infinite, in which case size will emit an error or not return.
Element retrieval operations head, last, headOption, lastOption, and find. These select the first or last element of a collection, or else the first element matching a condition. Note, however, that not all collections have a well-defined meaning of what “first” and “last” means. For instance, a hash set might store elements according to their hash keys, which might change from run to run. In that case, the “first” element of a hash set could also be different for different runs of a program. A collection is ordered if it always yields its elements in the same order. Most collections are ordered, but some (such as hash sets) are not—dropping the ordering provides a little bit of extra efficiency. Ordering is often essential to give reproducible tests and help in debugging. That’s why Scala collections provide ordered alternatives for all collection types. For instance, the ordered alternative for HashSet is LinkedHashSet.
Subcollection retrieval operations takeWhile, tail, init, slice, take, drop, filter, dropWhile, filterNot, and withFilter. These all return some subcollection identified by an index range or a predicate.
Subdivision operations splitAt, span, partition, and groupBy, which split the elements of this collection into several subcollections.
Element tests exists, forall, and count, which test collection elements with a given predicate.
Folds foldLeft, foldRight, /:, :\, reduceLeft, reduceRight, which apply a binary operation to successive elements.
Specific folds sum, product, min, and max, which work on collections of specific types (numeric or comparable).
Cover · Overview · Contents · Discuss · Suggest · Glossary · Index