Scala 使用自定义操作符实现foldRight

Scala 使用自定义操作符实现foldRight,scala,Scala,继续练习,我正在IndexedSeq类型上实现foldRight 由于foldRight将使用右关联性进行计算,因此我为模式匹配创建了以下操作符 object :++ { def unapply[T](s: Seq[T]) = s.lastOption.map(last => (last, s.take(s.length - 1))) } 然后实施为: object IndexedS

继续练习,我正在
IndexedSeq
类型上实现
foldRight

由于foldRight将使用
右关联性进行计算
,因此我为模式匹配创建了以下操作符

object :++ {
  def unapply[T](s: Seq[T]) = s.lastOption.map(last => 
                                                  (last, s.take(s.length - 1)))
}
然后实施为:

object IndexedSeqFoldable extends Foldable[IndexedSeq] {
  override def foldRight[A, B](as: IndexedSeq[A])(z: B)(f: (A, B) => B): B = {
    def go(bs: Seq[A], acc: B): B = bs match {
        case x :++ xs => go(xs, f(x, acc)) 
        case _ => acc
    }
    go(as, z)
  }

忽略可以使用
foldLeft
编写
foldRight
的事实,我的方法在性能、可读性或您的标准方面如何?在惯用的Scala方面