小编obl*_*ion的帖子

编写一个返回Nothing的scala方法

- >我们write a scala method的退货类型Nothing怎么样?

- >我们ever need to write such methods呢?有useful scenarios吗?

scala

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

在Scala中找到两个字符串之间的最长公共子字符串的功能方法

这是一个imperative解决方案:

def longestCommonSubstring(a: String, b: String) : String = {
    def loop(m: Map[(Int, Int), Int], bestIndices: List[Int], i: Int, j: Int) : String = {
      if (i > a.length) {
        b.substring(bestIndices(1) - m((bestIndices(0),bestIndices(1))), bestIndices(1))
      } else if (i == 0 || j == 0) {
        loop(m + ((i,j) -> 0), bestIndices, if(j == b.length) i + 1 else i, if(j == b.length) 0 else j + 1)
      } else if (a(i-1) == b(j-1) && math.max(m((bestIndices(0),bestIndices(1))), m((i-1,j-1)) + 1) …
Run Code Online (Sandbox Code Playgroud)

scala

2
推荐指数
3
解决办法
992
查看次数

如何从Future [Iterator]创建一个来源?

我有一个Future[Iterator].我想将这个迭代器提供给我的Stream.在这里,我仍然想像Iterator一样构建一个Source,就像我们使用的那样Source.fromIterator.

但是,Source.fromIterator由于Future ,我不能在这里使用.

也许我可以使用,Source.fromFuture但是当我尝试使用它时,在我的情况下它实际上似乎并没有从Iterator创建一个Source.来自文档:

/**
   * Starts a new `Source` from the given `Future`. The stream will consist of
   * one element when the `Future` is completed with a successful value, which
   * may happen before or after materializing the `Flow`.
   * The stream terminates with a failure if the `Future` is completed with a failure.
   */
  def fromFuture[T](future: Future[T]): Source[T, NotUsed] =
    fromGraph(new FutureSource(future))
Run Code Online (Sandbox Code Playgroud)

scala stream akka akka-stream

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

如何通过使用 sbt-docker 或手动编写 docker 文件在 docker 中运行 sbt 项目?

我一直在努力学习在 docker 中运行一个 sbt 项目。我也想用喷雾。我正在遵循 sbt-docker 在 github 中提供的示例: https://github.com/marcuslonnberg/sbt-docker/tree/master/examples/package-spray 当我拉项目时,它工作正常,我可以运行docker 容器也是如此。

project > project > PackageSprayBuild.scala 中有一个文件我不知道这个文件是如何使用的。此外,给定的示例没有 plugins.sbt 文件。

然后我尝试创建我的单独项目。

我的plugins.sbt看起来像这样:

logLevel := Level.Warn

addSbtPlugin("se.marcuslonnberg" % "sbt-docker" % "1.2.0")
Run Code Online (Sandbox Code Playgroud)

我的build.sbt看起来与我上面提到的示例几乎相同。

name := "demo-docker-sbt"

version := "1.0"

scalaVersion := "2.11.7"

resolvers += "spray repo" at "http://repo.spray.io/"

libraryDependencies ++= Seq(
  "io.spray" % "spray-can" % "1.2.0",
  "io.spray" % "spray-routing" % "1.2.0",
  "com.typesafe.akka" %% "akka-actor" % "2.2.3")

enablePlugins(DockerPlugin)

// Make docker depend on the package task, which generates a …
Run Code Online (Sandbox Code Playgroud)

scala sbt playframework spray docker

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

仅当端口打开时如何杀死在端口上运行的进程?

目前,我可以使用以下命令终止端口上运行的进程:

//other scripts that should be executed
...........................
sudo kill $( sudo lsof -i:9005 -t )
...........................
//other scripts that should be executed
Run Code Online (Sandbox Code Playgroud)

现在,我想首先测试端口 9005 是否确实打开,然后只尝试杀死它。如果端口没有打开,我不想执行杀死脚本。我想确保无论端口是打开还是关闭,后续脚本都会执行。所以,我正在寻找类似的东西:

//other scripts that should be executed
.............
<test-if-port-9005-is-open>  && sudo kill $( sudo lsof -i:9005 -t )
.............
// other scripts that should be executed
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

unix linux bash

0
推荐指数
2
解决办法
4082
查看次数

标签 统计

scala ×4

akka ×1

akka-stream ×1

bash ×1

docker ×1

linux ×1

playframework ×1

sbt ×1

spray ×1

stream ×1

unix ×1