小编Saq*_*Ali的帖子

检测 utf8mb4 字符集要求

我们有一个仅支持 utf8 的 mySQL DB。但是我们得到了一些需要 utf8mb4 才能存储在 mySQL 中的数据源。我们如何检测(在 Java 中)字符串是否需要 utf8mb4 字符集?

java mysql string utf-8 utf8mb4

1
推荐指数
1
解决办法
1809
查看次数

减少期货清单

我有一个长时间运行的函数,它返回一个 future,如下所示:

def longRunningFunction(signs: List[String], numOfWords: Int)
    : Future[List[(String, Int)]] = Future{ /* computation */ }
Run Code Online (Sandbox Code Playgroud)

我需要按如下方式减少 Future 的输出:

val all = (6 to 24).map(i => longRunningFunction(signs, i))
                   .reduce(_ ::: _)
Run Code Online (Sandbox Code Playgroud)

但这似乎不起作用。有什么想法吗?

dictionary scala future

1
推荐指数
1
解决办法
2048
查看次数

计算任何项目在Scala列表中显示的次数

我有以下列表:

val list = List("this", "this", "that", "there", "here", "their", "where")
Run Code Online (Sandbox Code Playgroud)

我想计算"这个"或"那个"出现多少次.我可以这样做:

 list.count(_ == "this") + list.count(_ == "that")
Run Code Online (Sandbox Code Playgroud)

有最简洁的方法吗?

scala

0
推荐指数
1
解决办法
172
查看次数

如果那么在地图中的其他地方

什么是更简洁的方式来表示以下If if else:

val result = scores.map(score =>
  if (score == 0)
    ("retake", 1)
  else if (score < 0)
    ("fail", 1)
  else
    ("pass", 1)
)
Run Code Online (Sandbox Code Playgroud)

functional-programming scala

0
推荐指数
1
解决办法
650
查看次数