8000 scala_notes/README.md at master · blehman/scala_notes · GitHub
[go: up one dir, main page]

Skip to content

Latest commit

 

History

History
44 lines (38 loc) · 1.3 KB

README.md

File metadata and controls

44 lines (38 loc) · 1.3 KB

Scala Notes

Attempting to learn how to write scala code.

Examp 39FE le 1: coin flip

First we define a function called coinFlip that returns a value of the type 'String' and does not take an input.

scala> def coinFlip(): String = {
     | Random.nextBoolean match {
     | case true => "Heads."
     | case false => "Tails."
     | }
     | }

When random numbers are created, we match them based on the case being true or false, in which case we return the respective string.

Try it! coinFlip() res0: String = Heads.

scala> coinFlip() res2: String = Tails.

Scalding Notes

$cd source/science
follow directions: go/scaldingrepl  

Once scalding is running...

import scala.io.Source  
val alice = Source.fromURL("http://www.gutenberg.org/files/11/11.txt").getLines.toIterable  
alice.take(10).foreach { line: String => println(line)}  
val alicePipe = TypedPipe.from(alice)  
alicePipe.map { line => line.length }  
alicePipe.map { line => line.length }.limit(10).dump  
alicePipe.map { line => line.length }.filter { length: Int => length > 0 }.limit(10).dump  

...skip to tutorial: https://confluence.twitter.biz/display/ANALYTICS/Scalding+at+Twitter+Tutorial

$cd source/science

Now follow the instructions starting with mkdir src/scala/com/twitter/tweetcounter/

0