This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BeanShort( | |
@BeanProperty var name:String = "Nothing", | |
@BeanProperty var steps:List[String] = List("ZERO"), | |
@BeanProperty var args:Map[Int,String] = Map(1 -> "zero") | |
){ | |
override def toString() : String = "Name: " + getName() + ", Args: " + getArgs() + ",Steps: " + getSteps() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Date | |
import java.util.Calendar | |
object ImplicitsConversions extends App { | |
class DateHelper(n:Int){ | |
def days(when:String):Date = { | |
var date =Calendar.getInstance() | |
when match { | |
case "ago" => date.add(Calendar.DAY_OF_MONTH,-n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object RecursionMatcher extends App{ | |
def factorial(i:BigInt):BigInt = i match { | |
case _ if i == 1 => i | |
case _ => i * factorial(i - 1) | |
} | |
for(i <- 1 to 10) printf("%s: %s\n", i, factorial(i)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object MatcherOnTuples extends App { | |
def pointRef(i:Any) = i match { | |
case (x,y, 55) => printf("x y and 55") | |
case (x,y) => printf("Point X %s Y %s \n",x,y) | |
case (3) => printf("This is 3") | |
case (x) => printf("Point X %s \n",x) | |
} | |
pointRef( (1,2) ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def whatTodo(on:String):Unit = on match { | |
case "Monday" => println("Hard Work") | |
case "Friday" => println("Lazy Work") | |
case "Saturday" => println("Fun") | |
case "Sunday" => println("REST") | |
case _ => println("Code Scala") | |
} | |
val days = List("Monday","Wendsday","Friday","Sunday","Saturday") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
days.foreach(whatTodo _) | |
// Or a even more explicit version | |
days.foreach( o => whatTodo(o) ) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Color | |
case class Red(saturation: Int) extends Color | |
case class Green(saturation: Int) extends Color | |
case class Blue(saturation: Int) extends Color | |
def matcher(arg:Any): String = arg match { | |
case "Chowder" => "Make with clams" | |
case x: Int => "An Int with value " + x | |
case Red(100) => "Red sat 100" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object MatcherCaseClasses extends App { | |
import scala.reflect.BeanProperty | |
trait DayOfWeek{ | |
@BeanProperty var whatTodo:String | |
} | |
case class Monday(@BeanProperty var whatTodo:String) extends DayOfWeek | |
case class Saturday(@BeanProperty var whatTodo:String) extends DayOfWeek | |
case class Sunday(@BeanProperty var whatTodo:String) extends DayOfWeek |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object MatcherThisVar extends App { | |
class Sample{ | |
val max = 100 | |
val MIN = 0 | |
def process(input:Int){ | |
input match{ | |
case this.max => println("This max 100") | |
case MIN => println("MIN 0") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(reduce + '(1 2 3 4 5 6)) ;;; Result will be 21 |