本文整理汇总了Scala中scala.collection.immutable.Set类的典型用法代码示例。如果您正苦于以下问题:Scala Set类的具体用法?Scala Set怎么用?Scala Set使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Set类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: promote
//设置package包名称以及导入依赖的类
package acumen
package interpreters
package reference2012
import Interpreter._
import acumen.Errors._
import scala.collection.immutable.Set
def promote(f: Store => Store) : Eval[Unit] =
mkEval (s => ((), Set.empty, Set.empty, f(s)))
def pure[A](x:A) : Eval[A] = mkEval(s => (x, Set.empty, Set.empty, s))
def pass = pure(())
def getStore : Eval[Store] = mkEval(s => (s, Set.empty, Set.empty, s))
def modifyStore(f:Store => Store) : Eval[Unit] =
mkEval(s => ((), Set.empty, Set.empty, f(s)))
def logCId(id:CId) : Eval[Unit] =
mkEval (s => ((), Set(id), Set.empty, s))
def logReparent(o:CId, parent:CId) : Eval[Unit] =
mkEval(s => ((), Set.empty, Set((o,parent)), s))
def asks[A](f : Store => A) : Eval[A] =
getStore >>= ((s:Store) => pure(f(s)))
def sequence[A](es:List[Eval[A]]) : Eval[List[A]] = es match {
case Nil => pure(Nil)
case (e::es) => for (x <- e; xs <- sequence(es)) yield x::xs
}
def sequence_[A](es:List[Eval[A]]) : Eval[Unit] =
es match {
case Nil => pure(())
case (e::es) => e >> sequence_(es)
}
def mapM[A,B](f:A => Eval[B], xs:List[A]) : Eval[List[B]] =
sequence(xs map f)
def mapM_[A,B](f:A => Eval[B], xs:List[A]) : Eval[Unit] =
sequence_(xs map f)
def foldLeftM[A,B](a:A, f:(A,B) => Eval[A], l:List[B]) : Eval[A] =
l match {
case Nil => pure(a)
case (x::xs) => f(a,x) >>= (a1 => foldLeftM(a1,f,xs))
}
}