scala - 如何在 Scala 中组合 2 个迭代器?

标签 scala iterator scala-collections

abIterator[String] 的值类型。我需要c包含 a 的所有元素和 b .令人惊讶的是,我无法弄清楚如何实现这一目标。你能碰巧知道吗?

最佳答案

++运算符(operator)将完成这项工作。
一个例子:

scala> val a = "abcd".combinations(2)
//a: Iterator[String] = non-empty iterator

scala> val b = "efg".combinations(2)
//b: Iterator[String] = non-empty iterator

scala> val c = a++b
//c: Iterator[String] = non-empty iterator

scala> c.toList
//res0: List[String] = List(ab, ac, ad, bc, bd, cd, ef, eg, fg)

关于scala - 如何在 Scala 中组合 2 个迭代器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9047856/

相关文章:

scala - 获取 Scala 映射中的最大值以及键

scala - 如何简化 bool 元素的 foldLeft 操作?

java - 是否有一个 Java 类可以让我迭代最后 x 个元素?

c++ - 整个范围内的 std::for_each 没有方便的重载吗?

scala - 参数 : _* mean in Scala? 是什么意思

scala - Scala 中的多个 flatMap

scala - flatMap 应用于 List[Option[T]] 时的行为

scala - Spark/Scala 拆分

scala - akka.actor.ActorLogging不会通过logback记录异常的堆栈跟踪

c++ - 为什么不基于 const range 来使用 const_iterator?