相关疑难解决方法(0)

我什么时候应该在Scala中选择Vector?

似乎VectorScala收集派对迟到了,所有有影响力的博客帖子已经离开了.

在Java中ArrayList是默认的集合 - 我可能会使用,LinkedList但只有当我通过算法并且足够小心地进行优化时才会使用.在Scala中,我应该使用Vector我的默认设置Seq,还是尝试在List实际上更合适时使用?

scala vector scala-collections

186
推荐指数
4
解决办法
5万
查看次数

MatchError在匹配时收到IndexedSeq而不是LinearSeq

是否有理由match反对SeqIndexedSeq类型上使用不同于对类型的处理方式LinearSeq?对我来说,无论输入类型如何,下面的代码似乎应该完全相同.当然它不会或我不会问.

import collection.immutable.LinearSeq
object vectorMatch {
  def main(args: Array[String]) {
    doIt(Seq(1,2,3,4,7), Seq(1,4,6,9))
    doIt(List(1,2,3,4,7), List(1,4,6,9))
    doIt(LinearSeq(1,2,3,4,7), LinearSeq(1,4,6,9))
    doIt(IndexedSeq(1,2,3,4,7), IndexedSeq(1,4,6,9))
    doIt(Vector(1,2,3,4,7), Vector(1,4,6,9))
  }

  def doIt(a: Seq[Long], b: Seq[Long]) {
    try {
      println("OK! " + m(a, b))
    }
    catch {
      case ex: Exception => println("m(%s, %s) failed with %s".format(a, b, ex))
    }
  }

  @annotation.tailrec
  def m(a: Seq[Long], b: Seq[Long]): Seq[Long] = {
    a match {
      case Nil => b
      case firstA :: moreA => b …
Run Code Online (Sandbox Code Playgroud)

scala match

2
推荐指数
1
解决办法
1693
查看次数

标签 统计

scala ×2

match ×1

scala-collections ×1

vector ×1