ScalaSpark Review 6132014 Redo Week 1 First Scala

  • Slides: 9
Download presentation
Scala/Spark Review 6/13/2014 Redo Week 1 First Scala Course/Demo Scalatestest Spray Can (in Job.

Scala/Spark Review 6/13/2014 Redo Week 1 First Scala Course/Demo Scalatestest Spray Can (in Job. Server)/sbt

Recursion 3 exercises on Recursion Point is: to use matching as replacement for loops

Recursion 3 exercises on Recursion Point is: to use matching as replacement for loops Very few if/then statements in proper Scala code Example: Factorial w/wo if then

Factorial factorial(n: Int): Int={ if(n==0) 1 else n*factorial(n-1) }

Factorial factorial(n: Int): Int={ if(n==0) 1 else n*factorial(n-1) }

Factorial with match def factorial(n: Int): Int = n match{ case 0 => 1

Factorial with match def factorial(n: Int): Int = n match{ case 0 => 1 case _ => n*factorial(n-1) }

codingbat examples http: //codingbat. com/java/Recursion-1 , recursion 2 Doesn't cover backtracking Doesn't exists for

codingbat examples http: //codingbat. com/java/Recursion-1 , recursion 2 Doesn't cover backtracking Doesn't exists for scala, copy and paste questions and code up solns in unit test. Add maven artifact/scalatest

Maven/Scalatest Disable surefire tests. Have to add the Java unit tests separately. HW uses

Maven/Scalatest Disable surefire tests. Have to add the Java unit tests separately. HW uses @Run. With(class. Of[JUnit. Runner]) <group. Id>org. apache. maven. plugins</group. Id> <artifact. Id>maven-surefire-plugin</artifact. Id> <version>2. 7</version> <configuration> <skip. Tests>true</skip. Tests> </configuration>

Demo > cd Test. Scalatest ; mvn test Some strange looking patterns: Either do

Demo > cd Test. Scalatest ; mvn test Some strange looking patterns: Either do nested case statement or mixed if/case statements. Can't put conditionals in case () case _ => if (n<10 && n==7) 1 else if(n<10 && n!=7) 0 else if ((n%10)==7) 1+count 7(n/10) else count 7(n/10)

Spray. Can Scala server. Akka-io config, jetty config (servlets) Used in spark-job-server from Ooyala

Spray. Can Scala server. Akka-io config, jetty config (servlets) Used in spark-job-server from Ooyala Sbt; build. sbt or scala code. Build. sbt specify k/v pairs for config map Job-server doesn't use build. sbt. Replace with scala code/sbt api No blank lines in sbt. build at top; uses for delimiters. Opposite of xml

Spray Resources Spray. Examples from github Add build. sbt, plugins. sbt Doesn't exist in

Spray Resources Spray. Examples from github Add build. sbt, plugins. sbt Doesn't exist in Spray. Examples Match akka with spray-can versions java. lang. No. Such. Method. Error: akka. actor. Props$. apply(Lscala/Function 0; Lscal a/reflect/Class. Tag; )Lakka/actor/Props; at spray. can. Http. Ext. <init>(Http. scala: 153)