- 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.
推薦閱讀
- Learn Blockchain Programming with JavaScript
- 微信公眾平臺與小程序開發:從零搭建整套系統
- 自己動手寫Java虛擬機
- 深入實踐Spring Boot
- 數據結構(Python語言描述)(第2版)
- Learning Three.js:The JavaScript 3D Library for WebGL
- Hands-On Natural Language Processing with Python
- Android底層接口與驅動開發技術詳解
- OpenCV 4計算機視覺項目實戰(原書第2版)
- 移動互聯網軟件開發實驗指導
- Go語言底層原理剖析
- Everyday Data Structures
- 原型設計:打造成功產品的實用方法及實踐
- Qt 5.12實戰
- Mastering JavaScript Promises