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
class AuthenticatedRequest[A](val ids: List[String], request: Request[A]) extends WrappedRequest[A](request) | |
object AuthenticationAction extends | |
ActionBuilder[AuthenticatedRequest] with ActionTransformer[Request, AuthenticatedRequest] { | |
def transform[A](request: Request[A]) = Future.successful { | |
new AuthenticatedRequest(List("1", "2"), request) | |
} | |
} | |
def AutorizationAction(itemId: String) = new ActionTransformer[Request, AuthenticatedRequest] { |
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
try ( Transaction tx = graphDb.beginTx() ) | |
{ | |
// Database operations go here | |
tx.success(); | |
} |
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
trait Function { | |
def name: String | |
} | |
case class ShellFunction(name: String) extends Function | |
case class ScalaFunction(name: String) extends Function | |
val l: List[Option[Function]] = List(None, Some(ShellFunction("build")), None) | |
val resultUsingForConstruct = for ( | |
i <- l; |
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
abstract class Person(name:String) { | |
override def toString() = s"My name is $name" | |
} | |
class Sample(name:String) { | |
x => | |
def function1 = new Person("123") { | |
println(s"Dont know what is x here: $x ") | |
} | |
} |
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
trait Filtering extends IntQueue { | |
def filter(x:Int) : Boolean | |
abstract override def put(x:Int) {if (filter(x)) super.put(x)} | |
} | |
val filteringQueue = new BasicIntQueue with Filtering { | |
def filter(x: Int): Boolean = x > 0 | |
} | |
filteringQueue.put(-3) | |
filteringQueue.put(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
val p = println(_ : Any) | |
p((List[Int]() /: List(1,2,3))((x,y) => y::x)) | |
p((List(1,2,3) :\ List[Int]())((x,y)=> y:::List(x))) |
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 main(args: Array[String]) { | |
def getTitle(p: Publication): String = p.title | |
def getTitle2(p:Magazine) : String = p.title | |
printBookList(getTitle) //works because getTitle is a sub type | |
printBookList(getTitle2) //I know function parameters are contravariant but what will happen if this were to work? | |
} | |
class Publication(val title: String) | |
class Book(title: String) extends Publication(title) |
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 l = List(1,2,3) | |
//The Functor/Monad Connection Law: The Zeroth Law | |
p(l map (_*2)) | |
p(l flatMap(x => List(x*2))) | |
//Flatten revisited | |
val identity = (x:Int) => List(x) | |
p(s"Flatmap: ${l.flatMap(identity)}") | |
p(s"Flattening: ${l.map(identity).flatten}") |
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
println(Some(Dev(Nil)) flatMap { | |
x => haskell(x) flatMap { | |
(y => linux(y) flatMap { | |
(z => scala(z) map { | |
java(_) | |
}) | |
}) | |
} | |
}) |
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 RevisedAbstracts { | |
def main(args: Array[String]) { | |
val a = new Cow | |
a.eat(new Grass) | |
val pasture = new Pasture | |
val l = (new Shark) :: pasture.animals | |
val animal = l(0).asInstanceOf[Cow] | |
animal.eat(new Grass) | |
} |
OlderNewer