我开始使用tmux(我正在考虑从屏幕切换),但是当我将一个窗口分成多个窗格时,我很难说出哪个窗格是聚焦的.是否有配置自定义或可以更明确地突出显示焦点窗格的内容?
Play的主页说:
Play基于Akka构建,可为高度可扩展的应用程序提供可预测的最小资源消耗(CPU,内存,线程).
我想知道Akka在Play中的使用方式和位置,以及在Akka上使用Play构建的后果.
是否可以在文件中保存REPL会话?是否有最低版本的Scala需要这样做?我记得曾见过有人这样做,但我无法将其解决:帮助或文档.
如何将HList的类型作为String获取,以便我可以打印它.例如"Int :: Long :: String :: HNil"
val gen = Generic[?]
val typeString: String = ???
println("The type is " + typeString)
Run Code Online (Sandbox Code Playgroud)
我知道它的字符串不是很有用,通常你想要的类型 gen.Repr
在光滑的(1.0),是做什么的区别.where()
,.filter()
并.withFilter()
在表?
在API中,它们具有相似的签名,但不清楚它们是如何不同的:
def filter[T] (f: (E) ? T)(implicit wt: CanBeQueryCondition[T]): Query[E, U]
def where[T <: Column[_]](f: (E) ? T)(implicit arg0: CanBeQueryCondition[T]): Query[E, U]
def withFilter[T] (f: (E) ? T)(implicit arg0: CanBeQueryCondition[T]): Query[E, U]
Run Code Online (Sandbox Code Playgroud) 如何定义程序包范围的默认导入?我想定义一个p
这样的包
import p._
Run Code Online (Sandbox Code Playgroud)
相当于
import scala.util.Try
import scala.collection.mutable.Queue
Run Code Online (Sandbox Code Playgroud) 当涉及到原语的神奇转换时,Scala似乎表现得像Java:
val a: Int = 1
val b: Double = 2.3
println(a + b) // 3.3
println(Math.max(a, b)) // 2.3
Run Code Online (Sandbox Code Playgroud)
通常,这是我的代码中的错误来源.有没有办法禁用这些隐式转换,以便我的示例给出编译警告/错误?我真的宁愿写
print(a.toDouble + b)
println(Math.max(a.toDouble, b))
Run Code Online (Sandbox Code Playgroud)
我每次都需要这样的转换.
假设我的应用程序Move
在很长一段时间内反复使用了很多对象,其Move
定义如下:
sealed trait Player
case object P1 extends Player
case object P2 extends Player
case object P3 extends Player
case object P4 extends Player
sealed trait Key
case object Up extends Key
case object Down extends Key
case object Right extends Key
case object Left extends Key
case object Space extends Key
sealed trait Action
case object Press extends Action
case object Release extends Action
case class Input(key: Key, action: Action)
case class Move(input: Input, player: …
Run Code Online (Sandbox Code Playgroud) .toString
在不等待复合的情况下呼唤未来会导致不确定的结果.我的问题是为什么在scala 2.10.x和2.11.x中调用.toString
未完成的期货收益"List()"
?该实现似乎并未明确.
可以从REPL中观察到此行为:
scala> import scala.concurrent.Future, scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.ExecutionContext.Implicits.global
scala> Future(1).toString
res0: scala.concurrent.Future[Int] = Success(1)
scala> Future(1).toString
res1: scala.concurrent.Future[Int] = List()
Run Code Online (Sandbox Code Playgroud)
请注意,Scala 2.12.x可能会显式实现Future#toString
返回"Future(<not completed>)"
(源代码).
编辑:证明这不是来自REPL或"隐藏隐藏"的人工制品(-Yno-predef
删除所有默认隐含):
Future.scala:
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
object Main extends App {
System.out.println(Future(1).toString)
}
Run Code Online (Sandbox Code Playgroud)
build.sbt:
scalaVersion := "2.11.8"
scalacOptions := Seq(
"-deprecation",
"-encoding", "UTF-8",
"-feature",
"-unchecked",
"-Yno-predef",
"-Xfatal-warnings",
"-Xlint",
"-Yinline-warnings",
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-unused-import",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard",
"-Xfuture")
Run Code Online (Sandbox Code Playgroud) 该方法的目的是在列表中获取元素,直到达到限制.
例如
我想出了两个不同的实现
def take(l: List[Int], limit: Int): List[Int] = {
var sum = 0
l.takeWhile { e =>
sum += e
sum <= limit
}
}
Run Code Online (Sandbox Code Playgroud)
它很简单,但使用了可变状态.
def take(l: List[Int], limit: Int): List[Int] = {
val summed = l.toStream.scanLeft(0) { case (e, sum) => sum + e }
l.take(summed.indexWhere(_ > limit) - 1)
}
Run Code Online (Sandbox Code Playgroud)
它看起来更干净,但它更冗长,也许内存效率更低,因为需要一个流.
有没有更好的办法 ?