像这样,Scala 2.12中的并行集合可以直接导入
import scala.collection.parallel.immutable.ParVector
val pv = new ParVector[Int]
Run Code Online (Sandbox Code Playgroud)
但是为什么在Scala 2.13软件包中scala.collection.parallel似乎丢失了?
生态系统中有无数的开发工具和术语,例如语言服务器、构建服务器、Metals、BSP、LSP、Bloop、Zinc、Coursier、增量编译器、演示编译器等。
我想知道是否有人可以演示它们如何组合在一起并简要解释关系和差异。具体来说,我希望按照“理解 Scala FP 库”的思路给出图表和答案。例如,这是我的尝试
(Concept) (Example implementation)
--------------------------------------------------------------------
IDE Visual Studio Code
| |
Scala IDE plugin Metals Visual Studio Extension
| |
Language Server Protocol Microsoft LSP
| |
Scala language server Metals
| |
Build Server Protocol BSP from JetBrains and Scala Center
| |
Scala build server Bloop
| |
Build tool sbt
| |
Dependency resolution Coursier
| |
Incremental compiler Zinc
| |
Presentation compiler parser and typer phases of scalac
| …Run Code Online (Sandbox Code Playgroud) development-environment scala build-tools incremental-build scala-metals
给出以下元组列表......
val list = List((1, 2), (1, 2), (1, 2))
Run Code Online (Sandbox Code Playgroud)
...如何将所有值相加并获得这样的单个元组?
(3, 6)
Run Code Online (Sandbox Code Playgroud) 我正在研究 Scala Edition1 https://www.artima.com/pins1ed/traits.html编程中的特征一章中的代码示例
由于我的错字,遇到了一个奇怪的行为。尽管覆盖方法的返回类型Unit与String. 但是在对象上调用该方法时,它返回 Unit 但不打印任何内容。
trait Philosophical {
def philosophize = println("I consume memory, therefore I am!")
}
class Frog extends Philosophical {
override def toString = "green"
override def philosophize = "It aint easy to be " + toString + "!"
}
val frog = new Frog
//frog: Frog = green
frog.philosophize
// no message printed on console
val f = frog.philosophize
//f: Unit = ()
Run Code Online (Sandbox Code Playgroud)
但是当我在重写的方法中给出显式返回类型时,它给出了一个编译错误:
class Frog extends Philosophical …Run Code Online (Sandbox Code Playgroud) val i: java.lang.Integer = null
val o: Option[Int] = Option(i) // This yields Some(0)
Run Code Online (Sandbox Code Playgroud)
转换null: java.lang.Integer为 Scala的安全方法是什么Option[Int]?
考虑f由类型构造函数F[_]和适当类型参数化的方法A
def f[F[_], A](v: F[A]) = v
Run Code Online (Sandbox Code Playgroud)
让我们尝试将其应用于 new Bar
scala> class Bar
class Bar
scala> def f[F[_], A](v: F[A]) = v
def f[F[_], A](v: F[A]): F[A]
scala> f(new Bar)
^
error: no type parameters for method f: (v: F[A]): F[A] exist so that it can be applied to arguments (Bar)
--- because ---
argument expression's type is not compatible with formal parameter type;
found : Bar
required: ?F[?A]
^
error: type mismatch;
found : …Run Code Online (Sandbox Code Playgroud) scala type-inference implicit-conversion type-parameter type-constructor
我有一个案例课
case class Doc(title:String, ....)
Run Code Online (Sandbox Code Playgroud)
我想转换为lift-json JObject所以我可以更容易地使用JObject方法合并等.
关于存在主义类型的一点混乱.
这对我有用:
def valueOf(c: Class[_], name: String) {
type C = Class[T] forSome {type T <: Enum[T]}
Enum.valueOf(c.asInstanceOf[C], name)
}
Run Code Online (Sandbox Code Playgroud)
但这不是:
def valueOf(c: Class[_], name: String) {
type T = T forSome {type T <: Enum[T]}
Enum.valueOf(c.asInstanceOf[Class[T]], name)
}
Run Code Online (Sandbox Code Playgroud)
在我看来,这两个表达式都相当于:
Enum.valueOf(z.asInstanceOf[Class[T] forSome {type T <: Enum[T]}], name)
Run Code Online (Sandbox Code Playgroud)
但斯卡拉说,这只是我的想法:
inferred type arguments [T] do not conform to method valueOf's type parameter bounds [T <: Enum[T]]
Enum.valueOf(c.asInstanceOf[Class[T]], name)
^
Run Code Online (Sandbox Code Playgroud) 我想在application.conf一个变量中定义一个字符串列表。目前在 application.conf 中我有这样的内容:
some.env.variable = ["a", "b"]
Run Code Online (Sandbox Code Playgroud)
我试过:
some.env.variable = ${?I_AM_ENV}.split(",")
Run Code Online (Sandbox Code Playgroud)
但I_AM_ENV = a,b 它不起作用。
加载应用程序时出现错误:
Wrong value type at 'some.env.variable', expecting: list but got: string
Run Code Online (Sandbox Code Playgroud) 为什么List[scala.Int]类型擦除,以List[Object]同时Integer在List[java.lang.Integer]似乎会保留吗?例如,javap对于
object Foo {
def fooInt: List[scala.Int] = ???
def fooInteger: List[java.lang.Integer] = ???
}
Run Code Online (Sandbox Code Playgroud)
输出
public scala.collection.immutable.List<java.lang.Object> fooInt();
public scala.collection.immutable.List<java.lang.Integer> fooInteger();
Run Code Online (Sandbox Code Playgroud)
我们看到的Integer是第二种情况。文档状态
Object如果泛型类型中的所有类型参数都带有边界,或者类型参数不受限制,则将其替换。
这可能是由于“ bounds”子句引起的吗?如果是这样,此界限在哪里指定?
scala ×10
arrays ×1
build-tools ×1
enums ×1
java ×1
json ×1
lift ×1
optional ×1
overriding ×1
scala-2.13 ×1
scala-metals ×1
sum ×1
traits ×1
tuples ×1
type-erasure ×1
types ×1