Where is the method that puts AnyRef in a parameter?

In this James Irie blog, he writes:

In addition, Scala has an “option” method that advances the value of either Some (value) or None, depending on whether it is null or not ...

I cannot find this method optionanywhere in scaladoc.

Iulian Dragos The gdata client project contains a method that probably applies to James.

def option[A <: AnyRef](a: A): Option[A] =
  if (a eq null) None else Some(a)

Indicate where I can find this method in scaladoc.

PS I have a method that looks like this:

def permutations(s: String): List[String] = ...

I am in two minds as to whether I should change it to:

def permutations(s: Option[String]): List[String] = ...

null. String, , option, .

+3
2

factory :

scala> Option.apply("Test")                
res51: Option[java.lang.String] = Some(Test)

scala> Option.apply(null)  
res52: Option[Null] = None

... :

scala> Option("Test")  
res49: Option[java.lang.String] = Some(Test)

scala> Option(null)
res50: Option[Null] = None
+15
+1
source

Source: https://habr.com/ru/post/1790380/


All Articles