summaryrefslogblamecommitdiff
path: root/sources/scala/Option.scala
blob: 3c7abb70346fd097bc2efeeb475b12958b4d29fb (plain) (tree)
1
2
3
4
5
6
7
8
9
               
 
                   
 

                        
 
                                                   
                       



                                      
                                
                                    





                                         
package scala {

  trait Option[a] {

    def isNone: Boolean;
    def get: a;

    def map[b](f: a => b): Option[b] = this match {
      case None => None
      case Some(x) => Some(f(x))
    }

    def toList: List[a] = this match {
      case None => Predef.List()
      case Some(x) => Predef.List(x)
    }

    def print: Unit =
      System.out.println(this.toString())
  }
}