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
scala> val seq = (1 to 10000000).view.filter(_ % 2 == 0).map(x => x+1) | |
seq: scala.collection.SeqView[Int,Seq[_]] = SeqViewFM(...) | |
scala> seq.take(10) | |
res0: scala.collection.SeqView[Int,Seq[_]] = SeqViewFMS(...) | |
scala> seq.take(10).force | |
res1: Seq[Int] = Vector(3, 5, 7, 9, 11, 13, 15, 17, 19, 21) | |
scala> val seq = (1 to 10000000).filter(_ % 2 == 0).map(x => x+1) |
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
val time = Latency.measure[Unit](Kamon.metrics.histogram("awesomeHistogram")) | |
time(printInt(5)) | |
Latency.measure(Kamon.metrics.histogram("awesomeHistogram"))(printInt(5)) | |
def printInt(num: Int): Unit = { | |
print(num) | |
} |
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.InputStream | |
import akka.actor.{ Actor, ActorRef, Props, ActorSystem } | |
case class ProcessStringMsg(lineNumber: Int, fileName: String, string: String, fileSender: Option[ActorRef], listener: ActorRef) | |
case class StringProcessedMsg(words: Integer, fileSender: Option[ActorRef]) | |
case class FileReference(fileName: String, stream: InputStream) | |
case class ProcessedFile(fileName: String, totalNumWords: Int, timeElapsed: Long, onCompleteSignal: Boolean) | |
case class CaptureStream(fileName: String, numOfWords: Int, lineNumber: Int, onCompleteSignal: Boolean) | |
case class StartProcessFileMsg() |
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
/** | |
* Option Collections | |
* | |
* Some developers see Option as a safe replacement for null values, | |
* notifying users that the value may be missing and | |
* reducing the likelihood that its use will trigger a Null PointerException. | |
* Others see it as a safer way to build chains of operations, | |
* ensuring that only valid values will persist for the duration of the chain. | |
* | |
* The Option type is itself unimplemented but relies on two subtypes for the implementation: |
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
Optional<String> optional = Optional.of("Bam"); | |
if(optional.isPresent()) | |
{ | |
System.out.println(optional.get()); //Bam | |
} | |
optional = Optional.empty(); | |
System.out.println(optional.orElse("test")); //test |
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
let rec trace_insert ((x,d) as e) t = match t with | |
| Empty -> (Node(e,Empty,Empty), H x) | |
| Node((y,d'),l,r) -> if (y=x) then (Node(e,l,r),H x) | |
else if x<y then | |
let(t',tr) = trace_insert e l in ( Node((y,d'),t',r), L(y,tr) ) | |
else | |
let(t',tr) = trace_insert e r in ( Node((y,d'),l,t'), R(y,tr) ) | |
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
let rec trace_insert ((x,d) as e) t = match t with | |
| Empty -> (Node(e,Empty,Empty), H x) | |
| Node((y,d'),l,r) -> if (y=x) then (Node(e,l,r),H x) | |
else if x<y then | |
let(t',tr) = trace_insert e l in ( Node((y,d'),t',r), L(y,tr) ) | |
else | |
let(t',tr) = trace_insert e r in ( Node((y,d'),l,t'), R(y,tr) ) | |
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
let flip_flop () = | |
let counter = ref 0 | |
in | |
fun () -> (if(!counter = 0) then counter := 1 else counter := 0; !counter);; |
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
let sumOdd a b = | |
let rec inner a b = | |
if a>=b then b else a + (inner (a+2) b) | |
in | |
let (new_a,new_b) = | |
( | |
(if ((a mod 2) = 0) then (a+1) else 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
# let x = Some "test";; | |
val x : string option = Some "test" | |
# match x with | |
|None -> Printf.printf "saw none\n" | |
|Some v -> Printf.printf "saw %s\n" v;; | |
saw test | |
- : unit = () |
NewerOlder