- 基本数据结构
- 列表 List
- 集 Set:集没有重复。
- 元组 Tuple
- 元组是在不使用类的前提下,将元素组合起来形成简单的逻辑集合。
- 使用位置下标来读取对象,而且这个下标基于1。
- 元组可以很好的与模式匹配相结合。
- 在创建两个元素的元组时,可以使用特殊语法:->
- 映射 Map
- 它可以持有基本数据类型。
- 映射的值可以是映射甚至是函数。
- 选项Option
- Option是一个表示有可能包含值的容器。
- Option本身是泛型的,并且有两个子类:Some[T]或None。
- 我们建议使用getOrElse或模式匹配处理这个结果,getOrElse让你轻松定义一个默认值。
- 函数子(Functional Combinators)
- map:对列表中的每个元素应用一个函数,返回应用后的元素所组成的列表。
- foreach:
- 很像map,但没有返回值。
- foreach仅用于有副作用(side-effects)的函数。
- filter:移除任何对传入函数计算结果为false的元素。
- zip:将两个列表的内容聚合到一个对偶列表中。
- partition:将使用给定的的谓词函数分割列表。
- find:返回集合中的一个匹配谓词函数的元素。
- drop & dropWhile:
- drop将删除前i个元素。
- dropWhile将删除元素直到找到的一个匹配谓词函数的元素。
- foldLeft:0为初始值,m作为一个累加器。
- foldRight:和foldLeft一样,只是运行过程相反。
- flatten:将嵌套结构扁平化为一个层次的集合。
- flatMap:
- 是一种常用的组合子,结合映射[mapping]和扁平化[flattening]。
- flatMap需要一个处理嵌套列表的函数,然后将结果串联起来。
- 可以把它看做是“先映射后扁平化”的快捷操作。
- 扩展函数组合子:上面所展示的每一个函数组合子都可以用fold方法实现。
- Map?
- 所有展示的函数组合子都可以在Map上使用。
- Map可以被看作是一个二元组的列表,所以你写的函数要处理一个键和值的二元组。
Thursday, May 15, 2014
scala课堂 集合
Labels:
scala
Subscribe to:
Post Comments (Atom)
The casino is coming to my home with my mom - Dr.MCD
ReplyDeleteIf I get a chance to play at 서울특별 출장샵 the best 인천광역 출장안마 gaming 광양 출장샵 venues, then I will give my mom 충청북도 출장샵 a call and we can begin to sort out 포항 출장마사지 my
In short, Huuuge provide a comprehensive competition 토토사이트 structure that each challenges and rewards gamers who continue to play and progres inside the app. These are gamers who are motivated by the thrill of playing and the stimulation they expertise whereas playing in}. Rather than gaming to win or earn cash, they’re simply looking for a good time and a enjoyable journey, whether they win or lose. Multi-wheel, pinball and Monopoly versions are among the many extra attention-grabbing.
ReplyDelete