partitionMap
方法(或屬性)屬於 scala.collection.IndexedSeqView
特性(trait),其相關用法說明如下。
用法:
def partitionMap[A1, A2](f: A => Either[A1, A2]): (View[A1], View[A2])
將函數 f
應用於可迭代集合的每個元素並返回一對可迭代集合:第一個由 f
返回的值組成,這些值被包在 scala.util.Left 中,第二個由被包的值組成scala.util.Right.
例子:
val xs = Iterable(1, "one", 2, "two", 3, "three") partitionMap {
case i: Int => Left(i)
case s: String => Right(s)
}
// xs == (Iterable(1, 2, 3),
// Iterable(one, two, three))
類型參數:
- A1
第一個結果集合的元素類型
- A2
第二個結果集合的元素類型
值參數:
- f
'split function' 將此可迭代集合的元素映射到 scala.util.Either
返回:
一對可迭代集合:第一個由
f
返回的值組成,這些值被包在 scala.util.Left 中,第二個由被包在 scala.util.Right 中的值組成.繼承自:
- collection.IterableOps.partitionMap
源碼:
- Iterable.scala
相關用法
- Scala IndexedSeqView.permutations用法及代碼示例
- Scala IndexedSeqView.sizeIs用法及代碼示例
- Scala IndexedSeqView.sortBy用法及代碼示例
- Scala IndexedSeqView.groupMap用法及代碼示例
- Scala IndexedSeqView.groupMapReduce用法及代碼示例
- Scala IndexedSeqView.sliding用法及代碼示例
- Scala IndexedSeqView.combinations用法及代碼示例
- Scala IndexedSeqView.collectFirst用法及代碼示例
- Scala IndexedSeqView.sortWith用法及代碼示例
- Scala IndexedSeqView.groupBy用法及代碼示例
- Scala IndexedSeqView.unzip用法及代碼示例
- Scala IndexedSeqView.unzip3用法及代碼示例
- Scala IndexedSeqView.inits用法及代碼示例
- Scala IndexedSeqView.tails用法及代碼示例
- Scala IndexedSeqView.mkString用法及代碼示例
- Scala IndexedSeqView.lengthIs用法及代碼示例
- Scala IndexedSeqView.lazyZip用法及代碼示例
- Scala IndexedSeqView.transpose用法及代碼示例
- Scala IndexedSeqView.addString用法及代碼示例
- Scala IndexedSeqView.scanRight用法及代碼示例
- Scala IndexedSeqOps.lengthIs用法及代碼示例
- Scala IndexedSeq.collectFirst用法及代碼示例
- Scala IndexedSeq.elementWise用法及代碼示例
- Scala IndexedSeqOps.unzip用法及代碼示例
- Scala IndexedSeqOps.appended用法及代碼示例
注:本文由純淨天空篩選整理自scala-lang.org大神的英文原創作品 IndexedSeqView.partitionMap。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。