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 A extends App { | |
type T4 = (Int, String, Int, String) | |
val list = List( | |
(1, "A", 2, "B"), (3, "C", 4, "D"), | |
(5, "E", 6, "F"), (7, "G", 8, "H") | |
) | |
def convert(list: List[T4]) = list flatMap { t => (t._1, t._2) :: (t._3, t._4) :: Nil } |
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
/** | |
* Run a function on a given set of partitions in an RDD and pass the results to the given | |
* handler function. This is the main entry point for all actions in Spark. | |
*/ | |
def runJob[T, U: ClassTag](rdd: RDD[T], func: (TaskContext, Iterator[T]) => U, partitions: Seq[Int], resultHandler: (Int, U) => Unit): Unit = { | |
if (stopped.get()) { | |
throw new IllegalStateException("SparkContext has been shutdown") | |
} | |
val callSite = getCallSite | |
val cleanedFunc = clean(func) |
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 PF extends App { | |
val pf0: PartialFunction[Int, String] = { case 0 => "Zero" } | |
val pf1: PartialFunction[Int, String] = { case 1 => "One" } | |
val pf2: PartialFunction[Int, String] = { case 2 => "Two" } | |
val lifted: (Int) => Option[String] = pf0.orElse(pf1).orElse(pf2).lift | |
val res0: String = lifted(3) match { | |
case Some(v) => v |
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
# Default system properties included when running spark-submit. | |
# This is useful for setting default environmental settings. | |
# Example: | |
# spark.master spark://master:7077 | |
spark.eventLog.enabled true | |
spark.eventLog.dir file:///home/ozawa/sparkeventlogs | |
# spark.serializer org.apache.spark.serializer.KryoSerializer | |
# spark.driver.memory 5g | |
# spark.executor.extraJavaOptions -XX:+PrintGCDetails -Dkey=value -Dnumbers="one two three" |
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 akka.actor.{Actor, ActorSystem, Props} | |
import akka.pattern.ask | |
import akka.util.Timeout | |
import scala.concurrent.duration._ | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.concurrent.{Await, Future} | |
case object Message |
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.io.{Serializable => S} | |
case class A(i: Int) | |
/*case*/ object A | |
val a = A | |
if (a.isInstanceOf[S]) println("Ok") | |
else println("Wrong") |
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
case class Monkey(name: String, age: Int) | |
val Monkey(n, a) = Monkey("Theodor", 17) | |
println(n, a) |
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 FuturesExample { | |
def main(args: Array[String]) { | |
val executor = newFixedThreadPool(8) | |
implicit val executionContext = fromExecutorService(executor) | |
val futures: List[Future[Int]] = | |
Future[Int]{sleep(1000); 1} :: | |
Future[Int]{sleep(2000); 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 foo(a, b): | |
return lambda c: a + b + c | |
print foo(1, 2)(3) |
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
package spire.algebra | |
import spire.syntax.eq._ | |
trait MeetSemilattice[A] { self => | |
def meet(x: A, y: A): A | |
def partialOrder: PartialOrder[A] | |
def meetAlgebra: CSemigroup[A] = |