Fahad/CodeSamples/SequenceComprehensions.scala
changeset 46 79336e47e14d
parent 44 a751aa1ee4f7
equal deleted inserted replaced
45:7545b1bc1514 46:79336e47e14d
       
     1 
       
     2 case class Twice(i: Int) {                              
       
     3   def apply(x: Int, y: Int): Int = x * y
       
     4   //def unapply(z: Int): Option[Int] = if (z % 2 == 0) Some(z/2) else None
       
     5 }
       
     6 
       
     7 Twice(21) match {
       
     8   case Twice(n) => println(n)
       
     9 }
       
    10 
       
    11 Twice(21, 3) match {
       
    12   case Twice(n) => println(n)
       
    13 }
       
    14 
     1 
    15 
     2 package Main
    16 package Main
     3 
    17 
     4 object ComprehensionsTest extends App {
    18 object ComprehensionsTest extends App {
     5   def even(from: Int, to: Int): List[Int] =
    19   def even(from: Int, to: Int): List[Int] =