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
//sbt run | |
//or | |
//scalac GroupBy.scala; scala GroupByRun | |
import java.util.UUID | |
import scala.collection.immutable.HashMap | |
import scala.util.Random | |
import java.io._ | |
/** |
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 scala.collection.immutable.Stream | |
//create the Pascal triangle using scala Streams | |
object Pascal extends App { | |
def plus(a:Int, b:Int) = a+b | |
def map2(str:Stream[Int], f:(Int, Int) => Int):Stream[Int] = str match { //pattern matcher doesn't seem to work properly | |
case Stream.Empty => str | |
case _ #:: Stream.Empty => str | |
case a #:: tail => f(a, tail.head) #:: map2(tail, f) |
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 Main extends App { | |
/* | |
* Exploring lazy evaluation in Scala to replace all nodes in a tree with the minimum value of the tree in 1 pass | |
* thanks to @begeric | |
*/ | |
sealed trait Tree | |
case class Node(tl:Tree, v:Int, t2:Tree) extends Tree | |
case object Leaf extends Tree | |
/* | |
* we give a concrete tree as input and a lazy value min which will eventually contain the minimum of all nodes |