当前位置: 首页>>代码示例>>Scala>>正文


Scala GenTraversableOnce类代码示例

本文整理汇总了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
    }
  }
} 
开发者ID:typesafehub,项目名称:sbt-whitesource,代码行数:25,代码来源:package.scala

示例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
  }
} 
开发者ID:janzhou,项目名称:approxssd,代码行数:33,代码来源:FlatMapPartition.scala

示例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)
} 
开发者ID:stonexx,项目名称:utils,代码行数:20,代码来源:ProductOps.scala

示例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)
  }

} 
开发者ID:danielnixon,项目名称:extrawarts,代码行数:41,代码来源:GenTraversableOnceOpsTest.scala


注:本文中的scala.collection.GenTraversableOnce类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。