我有一个我希望案例匹配的序列.我的问题很简单:
以下两种情况是否相同?
case x :: Nil =>
case x :: xs =>
Run Code Online (Sandbox Code Playgroud)
我可以改为
case Nil =>
case x :: xs =>
Run Code Online (Sandbox Code Playgroud)
如何处理x :: Nil的情况?是否也符合Nil的情况?
我尝试使用以下行加载资源文件夹下的 application.conf:
val config = ConfigFactory.load(getClass.getResource("application.conf").getPath)
Run Code Online (Sandbox Code Playgroud)
但是,它失败并且未加载 application.conf。没有错误或任何情况。关于要寻找什么有什么想法吗?
我有一个这样的序列:
val l = Seq(1,2,3,4)
Run Code Online (Sandbox Code Playgroud)
我想转变为 List(Seq(1,2), Seq(2,3), Seq(3,4))
这是我尝试过的:
def getPairs(inter: Seq[(Int, Int)]): Seq[(Int, Int)] = l match {
case Nil => inter
case x :: xs => getPairs(inter :+ (x, xs.head))
}
Run Code Online (Sandbox Code Playgroud)
这奇怪似乎不起作用?有什么建议?
我有一个Seq看起来像这样的元组:
Seq[(Future[Iterable[Type1]], Future[Iterator[Type2]])]
Run Code Online (Sandbox Code Playgroud)
我想将其转换为以下内容:
Future[Seq([Iterable[Type1], [Iterable[Type2])]
Run Code Online (Sandbox Code Playgroud)
这甚至可能吗?
我有一个用例,我将读取一组键/值对,其中键只是一个字符串,值是一个 JSON。我必须将这些值作为 JSON 公开给 REST 端点,我将使用 kafka 流消费者来做。
现在我的问题是:
我如何处理 Kafka 分区?我打算为消费者使用火花流
制片人呢?我想以恒定的时间间隔从外部服务轮询数据,并将生成的键/值对写入 Kafka 主题。是流媒体制作人吗?
这甚至是使用 Kafka 的有效用例吗?我的意思是,我可以有另一个消费者组,将传入的键/值对记录到数据库中。这正是吸引我使用 Kafka 的原因,可以让多个消费群体做不同的事情!
我认为对主题进行分区是为了增加并行性,从而增加消费者吞吐量。与不分区相比,此吞吐量如何?我有一个用例,我必须确保排序,因此我无法对主题进行分区,但同时我希望为我的消费者提供非常高的吞吐量。我该怎么做?
有什么建议?
这是 Apache Kafka 0.9.0.0 的任何错误吗?我正在使用以下命令列出主题,即使服务器是在创建主题的情况下启动的,我也没有得到任何信息!
Joes-MacBook-Pro:kafka_2.11-0.9.0.0 joe$ bin/kafka-topics.sh --list --zookeeper localhost:2181
Joes-MacBook-Pro:kafka_2.11-0.9.0.0 joe$
Run Code Online (Sandbox Code Playgroud)
这是我用来启动 Apache Kafka 的命令:
bin/kafka-server-start.sh config/server.properties & bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test_topic
Run Code Online (Sandbox Code Playgroud)
围绕着大肆宣传的 Apache Kafka 尝试基本的东西对我来说越来越苛刻了。这是我几乎卡住的另一个例子!
对于我在GitHub上的一个项目,我想将其构建为docker映像并将其推送到我的docker hub。该项目是一个具有Scala代码库的sbt项目。
这是我的JenkinsFile的定义方式:
#!groovy
node {
// set this in Jenkins server under Manage Jenkins > Credentials > System > Global Credentials
docker.withRegistry('https://hub.docker.com/', 'joesan-docker-hub-credentials') {
git credentialsId: '630bd271-01e7-48c3-bc5f-5df059c1abb8', url: 'https://github.com/joesan/monix-samples.git'
sh "git rev-parse HEAD > .git/commit-id"
def commit_id = readFile('.git/commit-id').trim()
println comit_id
stage "build" {
def app = docker.build "Monix-Sample"
}
stage "publish" {
app.push 'master'
app.push "${commit_id}"
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试从我的Jenkins服务器运行此文件时,出现以下错误:
java.io.FileNotFoundException
at jenkins.plugins.git.GitSCMFile$3.invoke(GitSCMFile.java:167)
at jenkins.plugins.git.GitSCMFile$3.invoke(GitSCMFile.java:159)
at jenkins.plugins.git.GitSCMFileSystem$3.invoke(GitSCMFileSystem.java:161)
at org.jenkinsci.plugins.gitclient.AbstractGitAPIImpl.withRepository(AbstractGitAPIImpl.java:29)
at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.withRepository(CliGitAPIImpl.java:65)
at jenkins.plugins.git.GitSCMFileSystem.invoke(GitSCMFileSystem.java:157)
at jenkins.plugins.git.GitSCMFile.content(GitSCMFile.java:159)
at jenkins.scm.api.SCMFile.contentAsString(SCMFile.java:338)
at …Run Code Online (Sandbox Code Playgroud) 我正在阅读Scala书中的函数式编程和Monoids章节,他们讨论了一个如下所示的Monoid接口:
trait Monoid[A] {
def op(a1: A, a2: A): A
def zero: A
}
Run Code Online (Sandbox Code Playgroud)
稍后,他们通过扩展此接口来定义特定的Monoid实例.例如.,
val intMonoid = new Monoid[Int] {
...
}
val listMonoid = new Monoid[List[Int]] {
...
}
Run Code Online (Sandbox Code Playgroud)
我通过本章10阅读了几页,我遇到了"更高级的类型",根据本书,它是任何类型,它本身就是一种可以采用其他类型的类型.
trait Foldable[F[_]] {
...
...
}
Run Code Online (Sandbox Code Playgroud)
因此,可折叠的特性是根据书中较高的一种类型.我的问题是,Monoid [A]对我来说也符合'更高的kinded类型'定义,因为它可以采用List [A].我的理解是否正确?如果不是什么使得更高级的kinded类型在Scala中成为更高的kinded类型?
编辑:所以一元类型构造函数接受一个参数并生成一个类型.那么这个案子呢?
def listMonoid[A] = new Monoid[List[A]] {
...
...
}
Run Code Online (Sandbox Code Playgroud)
那么我的listMonoid函数是HKT吗?
我正在尝试用于理解来构造对象调用,这是我的简单实现:
object FuncA extends (String => Int => String) {
override def apply(str: String): Int => String = i => {
s"${(str.toInt + i).toString}"
}
}
object FuncB extends (String => Int) {
override def apply(str: String): Int = {
str.toInt
}
}
for {
funcAStr <- FuncA("1")(1)
funcBStr <- FuncB(funcAStr) // Fails here
} yield {
println(s"Final String incremented as int is $funcBStr")
}
Run Code Online (Sandbox Code Playgroud)
但是奇怪的是,我有一个问题,其中funcAStr被解释为Char而不是String。任何理想的原因是什么?
string functional-programming scala function-composition for-comprehension
我盲目地按照安装文档安装 Microk8s 并使用 kubeflow 配置,但遇到了如下错误:
https://charmed-kubeflow.io/docs/quickstart
joesan@joesan-InfinityBook-S-14-v5:~$ juju add-model kubeflow
ERROR opening API connection: starting proxy for api connection: connecting k8s proxy: Get "https://192.168.0.35:16443/api/v1/namespaces/controller-microk8s-localhost/services/controller-service": x509: certificate signed by unknown authority (possibly because of "crypto/rsa: verification error" while trying to verify candidate authority certificate "10.152.183.1")
Run Code Online (Sandbox Code Playgroud)
看起来有些证书不匹配,但如何解决这个问题?
编辑:我尝试删除控制器,但没有成功:
joesan@joesan-InfinityBook-S-14-v5:~$ juju kill-controller microk8s-localhost
WARNING! This command will destroy the "microk8s-localhost" controller.
This includes all machines, applications, data and other resources.
Continue? (y/N):y
Unable to open API: starting proxy for api connection: connecting k8s …Run Code Online (Sandbox Code Playgroud)