Scala中的基本集合类型是什么? [英] What is the basic collection type in Scala?

查看:147
本文介绍了Scala中的基本集合类型是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

或者换句话说,在Scala中相当于C#IEnumerable< T>我认为这是Seq [T],但我已经发现,HashMap不实现这一点,所以它不能是真的。



那么,是什么? / p>

解决方案

可遍历可迭代是scala集合的基本traits。实际上, Iterable 扩展 Traversable



从scala api doc for Iterable


可迭代集合的基本trait。

这是一个基础trait为所有Scala集合定义迭代器
方法逐个逐个集合的元素。


Traversable



< blockquote>

这是各种Scala集合的基本特征。它以
foreach 方法实现
所有集合的公共行为。


以下是 scala-lang网站的精彩图片代表scala集合层次结构(分别是mutable和immutable):





不可变:




Or in other words what is the equivalent of C# IEnumerable<T> in Scala? I thought it is Seq[T], but I already found out, that HashMap does not implement this, so it cannot be true.

So, what is it?

解决方案

Traversable and Iterable are base traits for scala collections. Actually, Iterable extends Traversable.

From scala api doc for Iterable:

A base trait for iterable collections.

This is a base trait for all Scala collections that define an iterator method to step through one-by-one the collection's elements.

And Traversable:

This is a base trait of all kinds of Scala collections. It implements the behavior common to all collections, in terms of a method foreach.

Here is a nice pics from scala-lang site that represents scala collections hierarchy (mutable and immutable respectively):

Immutable:

这篇关于Scala中的基本集合类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆