本文整理汇总了Scala中scala.collection.GenTraversableOnce类的典型用法代码示例。如果您正苦于以下问题:Scala GenTraversableOnce类的具体用法?Scala GenTraversableOnce怎么用?Scala GenTraversableOnce使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GenTraversableOnce类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: KeyByAndMergeSyntax
//设置package包名称以及导入依赖的类
package sbtwhitesource
import scala.collection.GenTraversableOnce
import scala.collection.mutable
object `package` {
implicit class KeyByAndMergeSyntax[A](val _xs: GenTraversableOnce[A]) extends AnyVal {
def keyByAndMerge[K](keyFn: A => K, merge: (A, A) => Option[A]): Map[K, A] = {
val m = mutable.Map.empty[K, A]
for (elem <- _xs) {
val key = keyFn(elem)
val value = m get key match {
case None => elem
case Some(a) =>
merge(a, elem) getOrElse
(sys error s"Multiple elements for the same key $key:\n\t$a\n\t$elem")
}
m(key) = value
}
m.toMap
}
}
}
示例2: FlatMapPartition
//设置package包名称以及导入依赖的类
package org.janzhou.nvmr.partition
import scala.reflect.ClassTag
import scala.collection.GenTraversableOnce
import org.janzhou.nvmr.pmemory._
import org.janzhou.nvmr.console
class FlatMapPartition[T:ClassTag, U:ClassTag](
@transient private var p:Partition[U],
@transient private var f:(U => GenTraversableOnce[T])) extends Partition[T] {
override def depends:Set[Partition[_]] = {
if( computed ) {
if( cached ) {
Set[Partition[_]]()
} else {
Set[Partition[_]](this)
}
} else {
p.depends
}
}
override def one = {
console.debug("flatMap " + id)
val cache = p.content.flatMap(f)
p = null
f = null
cache
}
}
示例3: ProductOps
//设置package包名称以及导入依赖的类
package com.github.stonexx.scala.util
import scala.collection.GenTraversableOnce
final class ProductOps(val self: Product) extends AnyVal {
@inline def isDefinedAny: Boolean = self.productIterator.exists {
case null | None => false
case col: GenTraversableOnce[_] if col.isEmpty => false
case arr: Array[_] if arr.isEmpty => false
case _ => true
}
@inline def isEmptyAll: Boolean = !isDefinedAny
}
trait ToProductOps {
implicit def toProductOps(x: Product): ProductOps = new ProductOps(x)
}
示例4: GenTraversableOnceOpsTest
//设置package包名称以及导入依赖的类
package org.danielnixon.extrawarts
import org.scalatest.FunSuite
import org.wartremover.test.WartTestTraverser
import scala.collection.GenTraversableOnce
class GenTraversableOnceOpsTest extends FunSuite {
val list: GenTraversableOnce[Int] = Nil
test("can't use GenTraversableOnce#reduce") {
val result = WartTestTraverser(GenTraversableOnceOps) {
println(list.reduce(_ + _))
}
assertResult(List("[wartremover:GenTraversableOnceOps] GenTraversableOnce#reduce is disabled - use GenTraversableOnce#reduceOption or GenTraversableOnce#fold instead"), "result.errors")(result.errors)
assertResult(List.empty, "result.warnings")(result.warnings)
}
test("can't use GenTraversableOnce#reduceRight") {
val result = WartTestTraverser(GenTraversableOnceOps) {
println(list.reduceRight(_ + _))
}
assertResult(List("[wartremover:GenTraversableOnceOps] GenTraversableOnce#reduceRight is disabled - use GenTraversableOnce#reduceRightOption or GenTraversableOnce#foldRight instead"), "result.errors")(result.errors)
assertResult(List.empty, "result.warnings")(result.warnings)
}
test("GenTraversableOnceOps wart obeys SuppressWarnings") {
val result = WartTestTraverser(GenTraversableOnceOps) {
@SuppressWarnings(Array("org.danielnixon.extrawarts.GenTraversableOnceOps"))
val foo = {
println(list.reduce(_ + _))
println(list.reduceRight(_ + _))
}
}
assertResult(List.empty, "result.errors")(result.errors)
assertResult(List.empty, "result.warnings")(result.warnings)
}
}