Swift 中是否有与 Scala 的原始字符串或 C# 中的逐字字符串文字等效的功能?
没有转义字符的原始字符串示例(语法不正确):
val secretKey = """long\^578arandom&61~8791escaped&*^%@(chars"""
Run Code Online (Sandbox Code Playgroud)
我试过简单地掌握语言文档,但还没有找到功能等效的东西。
我目前正在做最高尚的编程工作,为Json编码/解码编写测试.我使用Argonaut.io的Json和Scalatest我的测试框架.在scalatest下,===断言验证期间的使用在发生故障时提供了额外的信息,而使用==简单地给出了这一点org.scalatest.exceptions.TestFailedException was thrown..但是,scala编译器并不满意.这是代码:
val default = new Broadcast("default", "default", "default")
test("Should parse out network when present") {
val hcursor = testHCursor(jsonPath + "complete-broadcast.json")
val actualNetwork = Parser.BroadcastDecodeJson(hcursor)
.getOr(default)
.network
assert(actualNetwork === "ESPNU")
}
Run Code Online (Sandbox Code Playgroud)
这喷出了这个:
[info] Compiling 1 Scala source to /home/vagrant/waltercamp/waltercamp-dataservice/target/scala-2.10/test-classes...
[error] /home/vagrant/waltercamp/waltercamp-dataservice/src/test/scala/io/ptx/waltercamp/schedules/BroadcastParserSuite.scala:16: type mismatch;
[error] found : actualNetwork.type (with underlying type String)
[error] required: ?{def ===(x$1: ? >: String("ESPNU")): ?}
[error] Note that implicit conversions are not …Run Code Online (Sandbox Code Playgroud) 标题说明了一切.我确定这是一个小的东西,但我已经在这几个小时,并不能让它舔.
我的project文件夹看起来像这样
project/
project/*
target/*
Build.scala
plugins.sbt
Run Code Online (Sandbox Code Playgroud)
plugins.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.0-M1")
Run Code Online (Sandbox Code Playgroud)
Build.scala
import sbt._
import Keys._
object BuildSettings {
val buildName = "ASDF"
val buildOrganization = "BLAH"
val buildVersion = "0.1-SNAPSHOT"
val buildScalaVersion = "2.10.4"
val buildSettings = Defaults.defaultSettings ++ Seq(
organization := buildOrganization,
version := buildVersion,
scalaVersion := buildScalaVersion,
shellPrompt := ShellPrompt.buildShellPrompt,
scalacOptions ++= Seq("-encoding", "utf8", "-unchecked", "-deprecation", "-feature")
)
}
object ShellPrompt {
object devnull extends …Run Code Online (Sandbox Code Playgroud) 我正在尝试解码一些真正糟糕的 JSON。每个对象的类型信息都在标记为type、 ie"type": "event"等的字段中编码。我使用Circe进行 JSON 编码/解码。该库使用类型类,其中相关的类型类是def apply(c: HCursor): Decoder.Result[A]. 问题是任何解码器都对类型不变,A. 这是一个具体的例子
sealed trait MotherEvent {
val id: UUID
val timestamp: DateTime
}
implicit val decodeJson: Decoder[MotherEvent] = new Decoder[MotherEvent] {
def apply(c: HCursor) = {
c.downField("type").focus match {
case Some(x) => x.asString match {
case Some(string) if string == "flight" => FlightEvent.decodeJson(c)
case Some(string) if string == "hotel" => // etc
// like a bunch of these
case None => …Run Code Online (Sandbox Code Playgroud)