我想知道isSorted()scala中是否存在任何函数.
问题:检查是否List[Int]已排序,如果没有删除最小数字并再次List[Int]进行排序?
我只想要1或2行程序.
这是我的 proto 文件的样子:
option java_package = "com.test.report";
message ClientRecord
{
optional string cust_id = 1;
optional double tx_bytes = 2;
optional double rx_bytes = 3;
optional string source_id = 4;
optional string dest_id = 5;
}
message ClientRecords
{
repeated ClientRecord record = 1;
}
Run Code Online (Sandbox Code Playgroud)
我能够在 python 中编写 protobuf 生成器/解码器,但是如何在 Scala/Java 中编写它。谁能帮我在 Scala 中为我的示例编写一个生成器?
def MyFun(result: ListBuffer[(String, DateTime, List[(String, Int)])]):
String = {
val json =
(result.map {
item => (
("subject" -> item._1) ~
("time" -> item._2) ~
("student" -> item._3.map {
student_description=> (
("name" -> lb_result._1) ~
("age" -> lb_result._2)
)
})
)
}
)
val resultFormat = compact(render(json))
resultFormat
}
Run Code Online (Sandbox Code Playgroud)
错误1:org.joda.time.DateTime => org.json4s.JsonAST.JValue没有隐式视图.("subject" - > item._1)〜
错误2:类型Nothing => org.json4s.JsonAST.JValue的分散隐式扩展从特征中的方法seq2jvalue开始JSONDSL val resultFormat = compact(render(json))
例如:
val xs = List((1,ArrayBuffer(900.0, 400.0))
(2,ArrayBuffer(2000.0, 800.0))
(3,ArrayBuffer(1500.0, 600.0, 700.0, 1100.0)))
Run Code Online (Sandbox Code Playgroud)
ArrayBuffer 是可种植的。
如何添加 的值ArrayBuffer?
输出应如下所示:
List((1, 1300.0)
(2, 2800.0)
(3, 3900.0))
Run Code Online (Sandbox Code Playgroud)
如何在scala中编写脚本?
我收到以下错误:
val formatter = ISODateTimeFormat.dateTimeParser()
scala> val date2 = "Tue Dec 29 11:11:30 IST 2015"
date2: String = Tue Dec 29 11:11:30 IST 2015
scala> formatter.parseDateTime(date2)
java.lang.IllegalArgumentException: Invalid format: "Tue Dec 29 11:11:30 IST 2015" is malformed at "ue Dec 29 11:11:30 IST 2015"
Run Code Online (Sandbox Code Playgroud)
如何解决以下错误??
例如,我的列表是:
list_1 = [ '[1234,', '4567,', '19234,', '786222]' ]
Run Code Online (Sandbox Code Playgroud)
并且预期的输出是:
list_1 = [1234, 4567, 19234, 786222]
Run Code Online (Sandbox Code Playgroud)