如何在IntelliJ中增加输出行的数量,以便在Scala工作表中不再收到此消息:
Output exceeds cutoff limit.
Run Code Online (Sandbox Code Playgroud)
Fedora 25. sbt 已安装,我一直在使用它,可能上次是一周前。但是今天没有找到。
$ sbt
bash: sbt: command not found...
Install package 'sbt' to provide command 'sbt'? [N/y]
Run Code Online (Sandbox Code Playgroud)
尝试重新安装,但 dnf 知道我在做什么
$ sudo dnf install sbt
[sudo] password for xxx:
Last metadata expiration check: 0:31:12 ago on Thu Apr 27 19:39:34 2017.
Package sbt-0.13.15.2-2.noarch is already installed, skipping.
Dependencies resolved.
Nothing to do.
Complete!
Run Code Online (Sandbox Code Playgroud)
检查安装位置,但没有运气
$ which sbt
/usr/bin/which: no sbt in (/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/xxx/.local/bin:/home/xxx/bin)
Run Code Online (Sandbox Code Playgroud)
我猜问题出在我的 $PATH 中,但是我没有改变它,尽管我已经安装了一些软件包
$ echo $PATH
/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/xxx/.local/bin:/home/xxx/bin
Run Code Online (Sandbox Code Playgroud)
最后,我确实在 /usr/share/sbt/bin/ 中找到了一个名为 sbt-launch.jar 的 jar,但我认为 /usr/share 从来没有成为我的 $PATH …
我有两个由 Docker Swarm 运行的容器:
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
18f1e7d79f5b default/image1:latest "/bin/sh -c 'java ..." 12 hours ago Up 12 hours image1.1.x56zz152kmqtqpxzle5nkbs8r
11d1f05fcff1 default/image2:latest "java -cp /app/sca..." 13 hours ago Up 13 hours image2.1.ljztzeeh8i5r6ebr3n4hcj45e
$ docker stats --no-stream
CONTAINER CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
18f1e7d79f5b 0.92% 0B / 0B 0.00% 648B / 0B 0B / 0B 0
11d1f05fcff1 0.91% 0B / 0B 0.00% 39.9MB / 26.9MB …Run Code Online (Sandbox Code Playgroud) 我有这样的模型:两个枚举和一个案例类,有两个这些枚举类型的字段:
// see later, why objects are implicit
implicit object Fruits extends Enumeration {
val Apple = Value("apple")
val Orange = Value("orange")
}
implicit object Vegetables extends Enumeration {
val Potato = Value("potato")
val Cucumber = Value("cucumber")
val Tomato = Value("tomato")
}
type Fruit = Fruits.Value
type Vegetable = Vegetables.Value
case class Pair(fruit: Fruit, vegetable: Vegetable)
Run Code Online (Sandbox Code Playgroud)
我想使用spray-json解析/生成与Pairs之间的JSON.我不想JsonFormat为水果和蔬菜宣布单独的s.所以,我想做这样的事情:
import spray.json._
import spray.json.DefaultJsonProtocol._
// enum is implicit here, that's why we needed implicit objects
implicit def enumFormat[A <: Enumeration](implicit enum: …Run Code Online (Sandbox Code Playgroud) 我想在元组上使用一些函数,它返回元组只有第一个元素被转换而其他元素没有变化.
这是Tuple2的天真版本:
def mapFirst[T, U, R](tuple: (T, U))(f: T => R): (R, U) = tuple match {
| case (x, y) => f(x) -> y
| }
mapFirst((1, 2))(_ * 5) // returns (5, 2)
Run Code Online (Sandbox Code Playgroud)
虽然,它不觉得原生,我想要的是这样写:
(1, 2).mapFirst(_ * 5)
Run Code Online (Sandbox Code Playgroud)
我写了隐式转换然后:
class RichTuple[T, U](tuple: (T, U)) {
def mapFirst[R](f: T => R): (R, U) = tuple match {
case (x, y) => f(x) -> y
}
}
implicit def tuple2RichTuple[T, U](tuple: (T, U)): RichTuple[T, U] = new RichTuple(tuple)
(1, 2).mapFirst(_ …Run Code Online (Sandbox Code Playgroud) 我有类型字段的类Set[String].另外,我有这个类的对象列表.我想将所有这些对象集中的所有字符串收集到一个集合中.我已经可以这样做了:
case class MyClass(field: Set[String])
val list = List(
MyClass(Set("123")),
MyClass(Set("456", "798")),
MyClass(Set("123", "798"))
)
list.flatMap(_.field).toSet // Set(123, 456, 798)
Run Code Online (Sandbox Code Playgroud)
它有效,但我认为,我可以只使用它flatMap,而不需要toSet调用.我试过这个,但它给出了编译错误:
// error: Cannot construct a collection of type Set[String]
// with elements of type String based on a collection of type List[MyClass].
list.flatMap[String, Set[String]](_.field)
Run Code Online (Sandbox Code Playgroud)
如果我将类型更改list为Set(即val list = Set(...)),则此类flatMap调用有效.
所以,我可以用某种方式Set.canBuildFrom或任何其他CanBuildFrom对象调用flatMap的List对象,所以,我会得到Set的结果呢?