collect
方法(或屬性)屬於 scala.Some
類(class),其相關用法說明如下。
用法:
@inline
final def collect[B](pf: PartialFunction[A, B]): Option[B]
返回一個scala.Some包含申請結果pf
對此scala.Option的包含值,如果此選項非空和 pf
為該值定義.否則返回None
。
值參數:
- pf
偏函數。
返回:
將
pf
應用於此 scala.Option 的值(如果可能)或None
的結果.例子:
// Returns Some(HTTP) because the partial function covers the case. Some("http") collect {case "http" => "HTTP"} // Returns None because the partial function doesn't cover the case. Some("ftp") collect {case "http" => "HTTP"} // Returns None because the option is empty. There is no value to pass to the partial function. None collect {case value => value}
繼承自:
- Option.collect
源碼:
- Option.scala
相關用法
- Scala Some.contains用法及代碼示例
- Scala Some.filter用法及代碼示例
- Scala Some.toRight用法及代碼示例
- Scala Some.flatMap用法及代碼示例
- Scala Some.orElse用法及代碼示例
- Scala Some.toLeft用法及代碼示例
- Scala Some.foreach用法及代碼示例
- Scala Some.exists用法及代碼示例
- Scala Some.map用法及代碼示例
- Scala Some.getOrElse用法及代碼示例
- Scala Some.orNull用法及代碼示例
- Scala Some.flatten用法及代碼示例
- Scala Some.unzip用法及代碼示例
- Scala Some.filterNot用法及代碼示例
- Scala Some.zip用法及代碼示例
- Scala Some.isEmpty用法及代碼示例
- Scala Some.unzip3用法及代碼示例
- Scala Some.fold用法及代碼示例
- Scala Some.nonEmpty用法及代碼示例
- Scala Some.toList用法及代碼示例
- Scala Some.isDefined用法及代碼示例
- Scala Some.forall用法及代碼示例
- Scala SortedSet.tails用法及代碼示例
- Scala SortedMap toString()用法及代碼示例
- Scala SortedSetOps.collectFirst用法及代碼示例
注:本文由純淨天空篩選整理自scala-lang.org大神的英文原創作品 Some.collect。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。