title: Understanding Some and Option in Scala
body: <p>I am reading this example from their <a href="https://docs.scala-lang.org/tour/singleton-objects.html" rel="noreferrer">docs</a>:</p>
  
  <pre><code>class Email(val username: String, val domainName: String)
  
  object Email {
    def fromString(emailString: String): Option[Email] = {
      emailString.split('@') match {
        case Array(a, b) =&gt; Some(new Email(a, b))
        case _ =&gt; None
      }
    }
  }
  
  println(Email.fromString("scala.center@epfl.ch"))
  val scalaCenterEmail = Email.fromString("scala.center@epfl.ch")
  scalaCenterEmail match {
    case Some(email) =&gt; println(
      s"""Registered an email
         |Username: ${email.username}
         |Domain name: ${email.domainName}
       """)
    case None =&gt; println("Error: could not parse email")
  }
  </code></pre>
  
  <p>My questions:</p>
  
  <ol>
  <li><p>What is <code>Some</code> and <code>Option</code>?</p></li>
  <li><p>What is a factory method (just some function that creates a new object and returns it?)</p></li>
  <li><p>What is the point of companion objects? Is it just to contain functions that are available to all instances of class? Are they like class methods in Ruby?</p></li>
  </ol>