给定方法调用的片段组合,返回选项类型.如果之前的调用返回None,我想调用下一个方法.我能够用这个片段完成这个
def amountToPay : Option[TextBoxExtraction] =
getMaxByFontsize(keywordAmountsWithCurrency) match {
case None => getMaxByFontsize(keywordAmounts) match {
case None => highestKeywordAmount match {
case None => getMaxByFontsize(amountsWithCurrency) match {
case None => highestAmount
case some => some
}
case some => some
}
case some => some
}
case some => some
}
Run Code Online (Sandbox Code Playgroud)
但它看起来很混乱.所以我希望有更好的方法来做到这一点.
Execution Context关于在Scala中执行期货的最佳/如何/最佳用途以及如何配置调度程序,存在很多问题.我仍然无法找到更长的列表,其中包含优缺点和配置示例.
我能找到的最好的是Akka文档:http://doc.akka.io/docs/akka/snapshot/scala/dispatchers.html和Play Documentation https://www.playframework.com/documentation/2.5.x/ThreadPools.
我想问一下除了scala.concurrent.ExecutionContext.Implicits.global你在日常开发生活中使用的Akka默认配置,当你使用它们时有什么配置,以及它们的优点和缺点.
以下是我已经拥有的一些内容:
scala.concurrent.ExecutionContext.Implicits.global在不确定时使用
使用方便
可能会耗尽你所有的CPU
更多信息:http://www.scala-lang.org/api/2.11.5/index.html#scala.concurrent.ExecutionContext
ExecutionContext.fromExecutor(new ForkJoinPool(1))play.api.libs.concurrent.Execution.Implicits._scala.concurrent.ExecutionContext.Implicits.global使用Play共享
更多信息:https://www.playframework.com/documentation/2.5.x/ThreadPools
ExecutionContext.fromExecutor(new ForkJoinPool(n)) based on an separated dispatcher . Thanks to Sergiy Prydatchenko
Run Code Online (Sandbox Code Playgroud) 为什么这两个命令的行为不同?
在生产模式下启动Play并启动dev模式有何不同?
activator run -Dconfig.file=/myConfig.conf # works
activator "run -Dconfig.file=/myConfig.conf" # works
activator "start -Dconfig.file=/myConfig.conf" # Works
activator start -Dconfig.file=/myConfig.conf # Doesn't, config file not found
Run Code Online (Sandbox Code Playgroud) 最近发布的Windows 10周年更新的新更新包括基于Ubuntu 14.04的 Linux子系统,现在我希望我的所有工作环境都在这个Linux子系统中.
我尝试使用官方网站https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/上的说明安装MongoDB
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt-get update
sudo apt-get install -y mongodb-org
Run Code Online (Sandbox Code Playgroud)
安装完成后我尝试运行mongodb
sudo service mongodb start
Run Code Online (Sandbox Code Playgroud)
但是有跟随错误
User@DESKTOP-TPQIRNP:/mnt/c/Users/User$ sudo service mongod start
initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused
mongod: unrecognized service
Run Code Online (Sandbox Code Playgroud)
如何安装最新的稳定版MongoDB而不出错?
问题描述
Scala StringOps提供了一个lines返回的方法Iterator[String].Java 11添加lines()了返回类型java.Stream[String].
在一个链式方法调用中
val text: String
text.lines.foldLeft("")(_ + _)
Run Code Online (Sandbox Code Playgroud)
代码将不再编译并抛出foldLeft未在java.Stream [String]上定义的exeption .据我所知,隐式解析不再适用,因为现在已经在java.String中找到了lines方法.
我如何表达我希望隐式被应用(没有parens的那个)而不是java.String.lines()
附加信息
linesIterator但它被弃用了.val text : StringOps 看起来很丑,但解决了它,但我对这个解决方案不满意是否有更可读和更强大(重构)的方式匹配像这样的案例类?
很长的案例类,有很多"字段".
case class Data(name: String, time: Long, ..., userId: Option[UUID] ..., orders: Int, ... ) //more fields fields more
Run Code Online (Sandbox Code Playgroud)
作品.但是当字段位置改变时容易出错.一个人最终算了_.
res match {
case data@Data(_,_,_,_,_,_,Some(id),_,_,_,6,_,_) => (id, data.orders)
case _ => ...
}
Run Code Online (Sandbox Code Playgroud)
也工作.对订单变更稳定.通过更多的检查来获得真正的麻烦.还必须重复阅读该值.
res match {
case data: Data if data.userId.isDefined && data.orders == 6 => (data.userId.get,data.orders)
case _ => ...
}
Run Code Online (Sandbox Code Playgroud)
有没有办法结合变体A和B来获得两种方法的好处?
使用激活器new启动激活器,您将获得项目种子列表,您还可以获得模板.是否有可能拥有自己的种子和模板的源/存储库,或者是否有可能配置为不使用类型安全的?
我希望实现这样的目标:
$~- activator new
Fetching the latest list of templates...
Browse the list of templates: http://my-templates
Choose from these featured templates or enter a template name:
1) My-Own-Seed
2) CompanyConfiguration
(hit tab to see a list of all templates)
Run Code Online (Sandbox Code Playgroud)
我知道g8,但我不想使用它,因为我喜欢与激活器的sbt紧密集成.
编辑:我在https://typesafe.com/activator/template/contribute找到了文档,但我不确定我是否可以实现种子只能在封闭环境中使用.
我们目前build.sbt拥有250多条生产线.
我们有两个问题:
当前的方法分组数据和评论:
// Plugins ///////////////////////////////////////////////////
enablePlugins(DockerPlugin)
// basic configuration : projects ///////////////////////////
name := """projectName"""
lazy val projectName =
(project in file(".")).....
Run Code Online (Sandbox Code Playgroud)
我们有一些配置逻辑,我们希望在不同的项目之间共享.
有没有办法包含其他*.sbt文件?或者你有一个建议如何解决这个问题而不诉诸写sbt插件?
从来没有想过会写一个永不回归的正则表达式.
正则表达式
/^((?:\d|\w{1,2}[-\d\s])(?:[-\s\d]|\w{1,2}[-\d\s])*\d)$/
Run Code Online (Sandbox Code Playgroud)
是为了匹配数字,以数字或两个字母开头,后跟一个空格或数字,并以数字结尾.在两者之间可以重复起始模式或者可以发生空白或短划线.
示例:1234,de-12943,EN-12de -50
以下示例代码不会终止:
红宝石
#!/usr/bin/ruby
string = "101000000750000000000000000000000001000038127OXMOO0OOOOO00000000000N9"
re = /^((?:\d|\w{1,2}[-\d\s])(?:[-\s\d]|\w{1,2}[-\d\s])*\d)$/
p re.match("101000000750000000000000000000000001000038127OXMOO0OOOOO00000000000N9")
Run Code Online (Sandbox Code Playgroud)
斯卡拉
"""^((?:\d|\w{1,2}[-\d\s])(?:[-\s\d]|\w{1,2}[-\d\s])*\d)$""".r findFirstIn "101000000750000000000000000000000001000038127OXMOO0OOOOO00000000000N9"
Run Code Online (Sandbox Code Playgroud)
删除锚点(^,$)可让正则表达式快速终止.
试过Ruby和Scala.
那里发生了什么?锚点不应该导致更快的终止吗?