contains 方法(或屬性)屬於 scala.Some 類(class),其相關用法說明如下。
用法:
final def contains[A1 >: A](elem: A1): Boolean
測試選項是否包含給定值作為元素。
這相當於:
option match {
case Some(x) => x == elem
case None => false
}
值參數:
- elem
要測試的元素。
返回:
true如果選項的元素等於(由==確定)到elem,則false否則.例子:
// Returns true because Some instance contains string "something" which equals "something". Some("something") contains "something" // Returns false because "something" != "anything". Some("something") contains "anything" // Returns false when method called on None. None contains "anything"繼承自:
- Option.contains
源碼:
- Option.scala
相關用法
- Scala Some.collect用法及代碼示例
- 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.contains。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
