Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/scala/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Scala 如何测试Map[String,List[Int]]中列表中的所有元素是否都包含负数?_Scala - Fatal编程技术网

Scala 如何测试Map[String,List[Int]]中列表中的所有元素是否都包含负数?

Scala 如何测试Map[String,List[Int]]中列表中的所有元素是否都包含负数?,scala,Scala,如何检查所有列表元素是否为负值——如果任何单个值为正值,则返回falseelsetrue scala> val checkNegative = Map( | "A" -> List(-1205678557, -1206583677, -1208669605, -1205679913), | "B" -> List(-396902501, -397202715, -396902501, -396902501, -396902501), |

如何检查所有列表元素是否为负值——如果任何单个值为正值,则返回
false
else
true

scala> val checkNegative = Map(
     |   "A" -> List(-1205678557, -1206583677, -1208669605, -1205679913),
     |   "B" -> List(-396902501, -397202715, -396902501, -396902501, -396902501),
     |   "C" -> List(-397502289, -397502289, -397502289, -397502289, -397502289),
     |   "D" -> List(-33902725, -33902725, -412803077, -33902725),
     |   "E" -> List(-458008664, -30433317),
     |   "F" -> List(300244, 300244, 300244, -396901292, 300244)
     | )
checkNegative: scala.collection.immutable.Map[String,List[Int]] = Map(E -> List(-458008664, -30433317), F -> List(300244, 300244, 300244, -396901292, 300244), A -> List(-1205678557, -1206583677, -1208669605, -1205679913), B -> List(-396902501, -397202715, -396902501, -396902501, -396902501), C -> List(-397502289, -397502289, -397502289, -397502289, -397502289), D -> List(-33902725, -33902725, -412803077, -33902725))

// How to get the value of `output`?
val output = Map(A -> true, B -> true, C -> true, D -> true, E -> true, F -> false)
val输出=checkNegative.mapValues(.forall(<0))
val输出=checkNegative.mapValues({.forall({<0))
val输出=for((键,值)0))
val输出=for((键,值)0))
val output = checkNegative.mapValues(_.forall(_ < 0))
val output = for((key, value) <- checkNegative) yield (key, !value.exists(_ > 0))