假设我有一个 bash 数组
X=("a" "b c" "-d" "k j", "-f")
Run Code Online (Sandbox Code Playgroud)
我想是否与开始过滤"-",并得到
("a" "b c" "k j")和("-d" "-f")分别。
我怎样才能做到这一点?
当我保存一个方法并稍后返回时,我所有的变量名都变成了 temp,我的所有参数都变成了 arg 并且代码缩进被更改了。关于如何解决这个问题的任何想法?
I'm a new Kotlin Programmer. I tried to change the app icon by deleting the ic_launcher.png files and replacing my own images. As i see that is ridiculous what i'm trying to do, i copied the "Main Activity.kt" and "main_activity.xml" files and created a new project. As i tried to copy the files into the new project, the program throws a lot of errors:
It didn't imported the "kotlinx" packet and didn't perceive the elements in the xml file. As …
拥有这些部门:
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-http-spray-json" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-stream" % akkaVersion,
"com.typesafe.akka" %% "akka-http" % akkaHttpVersion,
"com.typesafe.akka" %% "akka-actor-typed" % akkaVersion,
"com.typesafe.akka" %% "akka-stream" % akkaVersion,
"com.lightbend.akka" %% "akka-stream-alpakka-json-streaming" % akkaJsonStreaming,
"io.circe" %% "circe-generic-extras" % circeVersion,
"de.heikoseeberger" %% "akka-http-circe" % akkaHttpCirce,
"commons-codec" % "commons-codec" % commonsCodecVersion,
"org.scalatest" %% "scalatest" % scalaTestVersion % "it, test",
)
Run Code Online (Sandbox Code Playgroud)
当我运行时sbt assembly出现错误:
[error] (assembly) deduplicate: different file contents found in the following:
[error] /home/baku/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-annotations/2.10.5/jackson-annotations-2.10.5.jar:module-info.class
[error] /home/baku/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-core/2.10.5/jackson-core-2.10.5.jar:module-info.class
[error] /home/baku/.cache/coursier/v1/https/repo1.maven.org/maven2/com/fasterxml/jackson/core/jackson-databind/2.10.5/jackson-databind-2.10.5.jar:module-info.class
Run Code Online (Sandbox Code Playgroud)
知道如何解决这个问题吗?
我已经开始在 Coursera 上学习 Scala 并且有一些关于squareRootGuess实现的问题如下
我正在尝试实施标准来过滤sqrtGuess定义中的准确猜测,如下所示,但它给了我堆栈溢出错误。
def sqrtGuess(x: Double): Stream[Double] = {
def nextGuess(guess: Double): Double = (guess + x / guess)/2
def isSufficient(guess: Double): Boolean = math.abs(x - guess*guess)/x < 0.001
def guesses: Stream[Double] =
1 #:: guesses.map(nextGuess).filter(isSufficient)
guesses
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我们在外部定义 isSufficientsqrtGuess并应用于sqrtGuess流,效果会很好。
def sqrtGuess(x: Double): Stream[Double] = {
def nextGuess(guess: Double): Double = (guess + x / guess)/2
def guesses: Stream[Double] =
1 #:: guesses.map(nextGuess)
guesses
}
def isSufficient(guess: Double, x: …Run Code Online (Sandbox Code Playgroud) 我是 Scala 的新手,我正在尝试 PartialFunctions,这是测试功能的正确方法吗,因为一些教程遵循此方法工作,但对我不起作用?
代码:
object MyScalaApp extends App {
def try29{
val r = new PartialFunction[Int, Int]
{
def isDefinedAt(q: Int) = q < 0 // Applying isDefinedAt method
def apply(q: Int) = 12 * q // Applying apply method
}
val rr = new PartialFunction[Double, Double]
{
def isDefinedAt(q: Double) = {q < 0}
def apply(q: Double) = 12 * q
}
println(r(1))
println(r(2))
println(rr(-1))
println(rr(-2))
}
}
try29
}
Run Code Online (Sandbox Code Playgroud)
输出:
12
24
-12.0
-24.0
Run Code Online (Sandbox Code Playgroud)
为什么apply在不匹配第一个条件时会被调用? …
我是 Scala/函数式编程的新手,想了解我的以下解决方案是否适合函数式编程世界。如果有人可以建议我更好的方法,我将不胜感激。
问题陈述:打印一个列表的每一项,n次
解决方案:
import scala.collection.mutable.ListBuffer
object ListReplication extends App {
def printNTimes(items: List[Int], n: Int): ListBuffer[Int] = {
var outputList = new ListBuffer[Int]
def storeNTime(item: Int): Unit = {
for (_ <- 1 to n) outputList += item
}
for (item <- items) storeNTime(item)
outputList
}
val result = printNTimes(items = List(1,2,4), n = 3)
println(result)
}
Run Code Online (Sandbox Code Playgroud)