(A,B,C) => (A,(B,C))
这一步好说,直接取 head tail 就可以了。但是取每一个元素都做这个操作怎么搞?
1
nil3 2014-11-24 14:36:19 +08:00
scala> val a = Set(1, 2, 3)
a: scala.collection.immutable.Set[Int] = Set(1, 2, 3) scala> a map (x => Set(x, a diff Set(x))) res: scala.collection.immutable.Set[scala.collection.immutable.Set[Any]] = Set(Set(1, Set(2, 3)), Set(2, Set(1, 3)), Set(3, Set(1, 2))) 或者 scala> for (x <- a) yield Set(x, a diff Set(x)) res: scala.collection.immutable.Set[scala.collection.immutable.Set[Any]] = Set(Set(1, Set(2, 3)), Set(2, Set(1, 3)), Set(3, Set(1, 2))) |