我在文件中有以下定义Show.scala:
package com.example
trait Show[A] {
def show(a: A): String
}
object Show {
def apply[A](implicit sh: Show[A]): Show[A] = sh
//def show[A](a:A)(implicit sh: Show[A]) = sh.show(a)
def show[A: Show](a: A) = Show[A].show(a)
implicit class ShowOps[A: Show](a: A) {
def show = Show[A].show(a)
}
implicit val intCanShow: Show[Int] =
new Show[Int] {
override def show(a: Int): String = s"int $a"
}
}
Run Code Online (Sandbox Code Playgroud)
并在Main.scala:
package com.example
object Main extends App {
println(Show.show(344))
println(30.show)
}
Run Code Online (Sandbox Code Playgroud)
编译器抱怨:
[error] /home/developer/scala/show/src/main/scala/com/example/Main.scala:6:14: …Run Code Online (Sandbox Code Playgroud) 我有以下代码,并且想了解为什么在执行时立即停止:
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.model._
import akka.http.scaladsl.server.Directives._
import akka.stream.ActorMaterializer
import scala.io.StdIn
object WebServer {
def main(args: Array[String]) {
implicit val system = ActorSystem("my-system")
implicit val materializer = ActorMaterializer()
// needed for the future flatMap/onComplete in the end
implicit val executionContext = system.dispatcher
val route =
path("hello") {
get {
complete(HttpEntity(ContentTypes.`text/html(UTF-8)`, "<h1>Say hello to akka-http</h1>"))
}
}
val bindingFuture = Http().bindAndHandle(route, "localhost", 8080)
bindingFuture
.flatMap(_.unbind()) // trigger unbinding from the port
.onComplete(_ => system.terminate()) // and shutdown when done …Run Code Online (Sandbox Code Playgroud) 我正在使用https://github.com/sbt/sbt-git来获得自动版本控制的好处,如“ 使用Git进行版本控制 ”部分中所述。
我的build.sbt文件如下所示:
version := "0.1.0"
scalaVersion := "2.12.8"
scalacOptions ++= Seq(
"-encoding", "UTF-8", // source files are in UTF-8
"-deprecation", // warn about use of deprecated APIs
"-unchecked", // warn about unchecked type parameters
"-feature", // warn about misused language features
"-language:higherKinds", // allow higher kinded types without `import scala.language.higherKinds`
"-Xlint", // enable handy linter warnings
"-Xfatal-warnings", // turn compiler warnings into errors
"-Ypartial-unification" // allow the compiler to unify type constructors of different …Run Code Online (Sandbox Code Playgroud) 我正在使用https://www.testcontainers.org/modules/kafka/并希望配置容器,以便在测试开始之前确保 Kafka 已启动并运行。
怎么存档呢?
我有以下代码片段:
import Control.Applicative
import Data.Text
import Data.Attoparsec.Text
data GreetingYear = GreetingYear Text Int deriving Show
greetingYearParser :: Parser GreetingYear
greetingYearParser = GreetingYear <$> (string "hello" <|> string "bye")
<*> decimal
Run Code Online (Sandbox Code Playgroud)
当我使用它时,如下所示:
parse greetingYearParser "hello172"
Run Code Online (Sandbox Code Playgroud)
我有
Partial _
Run Code Online (Sandbox Code Playgroud)
为什么我没有收到:
Done "" (GreetingYear "hello" 172)
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我在 K8S 集群上部署了 Harbor,如下所示:
helm install dockistry harbor/harbor \
--set expose.type=ingress
Run Code Online (Sandbox Code Playgroud)
然后入口资源显示:
kubectl get ingress
NAME HOSTS ADDRESS PORTS AGE
dockistry-harbor-ingress core.harbor.domain,notary.harbor.domain xxx.xxx.100.61 80, 443 2m43s
Run Code Online (Sandbox Code Playgroud)
这HOSTS是错误的,希望更改它。我该如何编辑dockistry-harbor-ingress?
我试图了解https://hackage.haskell.org/package/base-4.14.0.0/docs/Data-Void.html并有以下示例:
let x :: Either Void Int; x = Left Void
Run Code Online (Sandbox Code Playgroud)
代码不会被编译。如何让它运行?
haskell ×3
scala ×3
akka ×2
akka-stream ×2
kubernetes ×2
akka-http ×1
git ×1
minio ×1
sbt ×1
sbt-git ×1