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
// Function "add" implemented in javascript | |
function add(x, y) { | |
return x + y; | |
} | |
// Function "add" implemented in Scala as javascript is actually implementing it behind the scenes | |
sealed abstract class DynamicType | |
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 A | |
class B extends A | |
class C extends B | |
val a = new A | |
val b = new B | |
val c = new C | |
def f[T : ClassTag](a: A) = a match { | |
case _: T => "is given type" |
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> import mq.models.place._ | |
import mq.models.place._ | |
scala> import mq.models._ | |
import mq.models._ | |
scala> val a = Airport(123, "slug", Address("US"), LatLng(1,-1), PlaceAttributes(), PoiAttributes(), AirportAttributes()) | |
a: mq.models.place.Airport = Airport(123,slug,Address(US,None,None,None,None,None),LatLng(1.0,-1.0),PlaceAttributes(None,List(),None),PoiAttributes(None,None,None,None,None,List(),List(),None,None,None,List(),List(),List(),List(),None,List()),AirportAttributes(,List(),None)) | |
scala> a.name(Some("foo")) |
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
// Given | |
trait Common | |
class A extends Common | |
class B extends Common | |
class C extends Common | |
// These are equivalent... |
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> class A { val prop = "a" } | |
scala> class B extends A { override val prop = "b" } | |
scala> class C extends B | |
scala> implicit class Foo(a: A) { def value = a.prop } | |
scala> implicit class Bar(b: B) { def value = b.prop } | |
scala> val c = new C | |
scala> c.value | |
res0: String = b | |
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
// DEMO CODE | |
import scala.concurrent.Future | |
import scala.concurrent.ExecutionContext.Implicits.global | |
def time[A](label: String, block: => Future[A]) = { | |
val t0 = System.nanoTime() | |
block.onComplete { | |
case _ => { | |
val t1 = System.nanoTime() |
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
@(place: Place) | |
<a href="@place.details.contact.website">Website</a> | |
------------------------------------------------------------------------ | |
<a href="{{website}}">Website</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
// Class | |
package presenters.poiattributes | |
import scala.language.implicitConversions | |
import play.api.templates.Html | |
trait AttributePresenter { | |
val identifier: String | |
val value: Any |
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
implicit class Unlessable[A](a: => A) { | |
def unless(p: => Boolean) = if (!p) Some(a) else None | |
} | |
implicit class Iffable[A](a: => A) { | |
def iff(p: => Boolean) = if (p) Some(a) else None | |
} | |
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
// reporting library | |
// http://stackoverflow.com/questions/9160001/how-to-profile-methods-in-scala | |
def perf[R](block: => R): Unit = { | |
val t0 = System.nanoTime() | |
block | |
val t1 = System.nanoTime() | |
val elapsed = (t1 - t0) / 1000000000f | |
println("Elapsed time: " + elapsed + "s") |