This file contains hidden or 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
abstract class PrintSomething() { | |
def apply(s: String): Unit | |
} | |
object PrintSomething { | |
/** | |
* @param printMethod a method that prints something | |
* @return a PrintSomething with an apply method | |
* equal to your printMethod |
This file contains hidden or 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
type PrintSomething = (String) => String | |
val printer1: PrintSomething = (s: String) => { | |
print("\nI love " + s) | |
s | |
} | |
val printer2: PrintSomething = (s: String) => { | |
print("\nI hate " + s) | |
s |
This file contains hidden or 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
update, I have a test case here: https://gist.github.com/Chandler/7766963 | |
I'm running it with multiple files as the input and cascading.hadoop.hfs.combine.files=true | |
When I run it against stock elephant bird it fails with the original error | |
"com.twitter.elephantbird.mapred.input.DeprecatedLzoTextInputFormat cannot be cast to org.apache.hadoop.mapred.FileInputFormat" | |
https://github.com/kevinweil/elephant-bird/pull/359 | |
When I run it with Dmitriy's elephant bird patch it fails with "DeprecatedInputFormatWrapper can not support RecordReaders that don't return same key & value objects. current reader class : class com.twitter.elephantbird.mapreduce.input.LzoLineRecordReader" |
This file contains hidden or 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
class myException extends Exception | |
object myObj { | |
val ex = myException | |
} | |
// <console>:11: error: not found: value myException | |
// val ex = myException |
This file contains hidden or 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
//this works | |
def checkUnauthorizedException[T](t: Try[T]): TestResult = | |
t match { | |
case Throw(e) if e.isInstanceOf[UnauthorizedException] => TestResult.Success | |
case _ => TestResult.fail("found " + t.toString() + " but expected Throw[UnauthorizedException]") | |
} | |
//possible to make this more generic? e.g. something like.. |
This file contains hidden or 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 MyException(errorCode: Int) extends RuntimeException | |
def onThrow[T <: Throwable](check: Check[T])(implicit m: Manifest[T]): Check[Try[_]] = | |
expected("A Throw(e: %s)".format(m.erasure)).exceptWhen { case Throw(NonFatal(e: T)) => check(e) } | |
val check = onThrow { | |
hasType[Unauthorized.type].on { e: ClientError => e.errorCause } | |
} | |
check(Throw(MyException(5))) |
This file contains hidden or 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 myMethod { | |
val a: Option[Int] = someOption() | |
if (a.isNone){ | |
//do a side effect (like increment a hadoop counter) | |
} | |
return a | |
} |
This file contains hidden or 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 sideEffect() { | |
//increment hadoop counter | |
} | |
val list = List(Some("a"),Some("b"),None, Some("e"), None) | |
val filtered = list.flatMap { x => | |
if(x.isEmpty) sideEffect() | |
x | |
} |
This file contains hidden or 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 WriteEvent(name: String, records: List[Int]) | |
case class SingleRecord(name: String, value: Int) | |
val events = List( | |
WriteEvent("follow", List(1,2,3)), | |
WriteEvent("block", List(2,3,4)), | |
WriteEvent("follow", List(5,6,7)) | |
) |
This file contains hidden or 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> def test(name: String = "joe"): Boolean = true | |
test: (name: String)Boolean | |
scala> val test: String => Boolean = { (name: String = "joe") => true } | |
<console>:1: error: ')' expected but '=' found. |