官术网_书友最值得收藏!

IterableOnceOps

IterableOnceOps represents a blueprint for the collections that can be traversed one or multiple times. It defines a few abstract methods that must be implemented by every collection and a number of concrete methods implemented in terms of an iterator available from IterableOnce. The concrete methods provide default, if possible, lazy, implementations and fall into one of the following categories:

  • Size operations: isEmpty, nonEmpty, size, knownSize, and isTraversableAgain check the collection for (non) emptiness or return its size. knownSize is an optimization that returns -1 if the size cannot be determined without iterating over the collection. isTraversableAgain returns false for IterableOnce.
  • Element tests: forall, exists, and count check whether all, at least one, or some number of elements satisfy the given predicate.
  • String operations: mkString and addString. These methods with different argument sets provide a possibility to build alternative string representation.
  • Conversions to another collections: copyToArray, toList, toMap, to, toSet, toSeq, toIndexedSeq, toBuffer, and toArray. These methods copy or convert an Iterable into another collection. The to method is special in this list because it allows us to return any type of the collection that has a Factory available. We will look at it in more detail soon.
  • Fold and reduce: foldLeft, foldRight, reduce, reduceLeft, reduceRightreduceOptionreduceLeftOption, and reduceRightOption apply a binary operation to the elements of the collection. The reduce*Option methods handle the case of an empty collection gracefully by returning None.
  • Numeric combinations: sum and product calculate the sum or product of the elements if there is an implicit Numeric[B] such that B >: A is available.
  • Ordering combinations:  min, minOption, max, maxOption, maxBy, maxByOption, minBy, and minByOption find an element of the collection that satisfies giving predicate if there is an implicit Ordering[B] with B >: A available. The *Option methods return None for an empty collection instead of throwing an exception.
  • Element retrieval: collectFirst and find. Choose an element that satisfies a given condition.
  • Equality: corresponds is an alternative way to compare collections. Satisfied if every element of this collection relates to matching element of another collection by given predicate.

Abstract methods fall into one of the following categories:

  • Subcollection retrieval: filter, filterNot, take, takeWhile, drop, dropWhile, slice, and span. Take or discard elements that satisfy the given predicate or range, from the whole collection or beginning of it. 
  • Mapping: map, flatMapcollect, and scanLeft. Transforms elements of the collection by applying some function and possibly filtering the results.
  • Zippers: zipWithIndex adds an index to all elements of the collection.
主站蜘蛛池模板: 洪泽县| 饶阳县| 张家口市| 靖远县| 陇南市| 东乡族自治县| 绍兴市| 遵化市| 淮南市| 石门县| 金昌市| 开平市| 黔南| 紫云| 西乌珠穆沁旗| 岳阳县| 安吉县| 沈丘县| 曲水县| 遂平县| 冀州市| 政和县| 张家界市| 彭水| 辰溪县| 承德县| 威海市| 富平县| 东乌珠穆沁旗| 镇雄县| 开平市| 巫溪县| 洪湖市| 高邮市| 抚远县| 大同县| 辽源市| 漠河县| 五大连池市| 罗定市| 嵊泗县|