- Learn Scala Programming
- Slava Schmidt
- 185字
- 2021-06-10 19:35:42
LinearSeq
Linear sequences have the notion of a head and a tail. The definition looks like trait LinearSeq[+A] extends Seq[A] with LinearSeqOps[A, LinearSeq, LinearSeq[A]] and the class diagram is shown here:
There are three representatives of LinearSeq, all are immutable:
- List defines three symbolic methods which provide a nice syntax for pattern-matching and building lists. :: prepends element to the list, ::: prepends all elements of a given list, and reverse_::: prepends all elements of a given list but in the reverse order.
- LazyList is a new immutable collection available since Scala 2.13. It implements a list with a head and a tail, which are not evaluated until needed. As it is superior to Stream, which is only lazy in the tail, Stream is now deprecated. LazyList has two additional methods, force which evaluates it, and lazyAppendAll which lazily appends a given collection to this list.
- Queue in this hierarchy is also immutable. It allows a first-in-first-out (FIFO) insertion and retrieval of the elements. For this functionality, it defines the enqueue, enqueueAll, dequeue, dequeueOption, and front methods.
推薦閱讀
- 現代C++編程:從入門到實踐
- Beginning C++ Game Programming
- Android開發精要
- Python從菜鳥到高手(第2版)
- Python零基礎快樂學習之旅(K12實戰訓練)
- Django Design Patterns and Best Practices
- 基于差分進化的優化方法及應用
- Easy Web Development with WaveMaker
- 編程與類型系統
- 深入剖析Java虛擬機:源碼剖析與實例詳解(基礎卷)
- Getting Started with Nano Server
- SQL Server 2008中文版項目教程(第3版)
- ArcGIS Blueprints
- Hybrid Mobile Development with Ionic
- 從Excel到Python:用Python輕松處理Excel數據