这不行吗?
> val setOfSets = Set[Set[String]]()
setOfSets: scala.collection.immutable.Set[Set[String]] = Set()
> setOfSets reduce (_ union _)
java.lang.UnsupportedOperationException: empty.reduceLeft
at scala.collection.TraversableOnce$class.reduceLeft(TraversableOnce.scala:152)
[...]
最佳答案
缩小(左右)不能应用于空集合。
从概念上讲:
myCollection.reduce(f)
类似于:
myCollection.tail.fold( myCollection.head )( f )
因此,集合必须至少包含一个元素。
关于scala - 减少一组空集是否有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6986241/