def common[T<:Equals](a: T, b: T): Option[T] = {
if(a == b) Some(a) else None
}
def common[T<:AnyVal](a: T, b: T): Option[T] = {
if(a == b) Some(a) else None
}
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
package presentation.json | |
import org.scalautils._ | |
import Accumulation._ | |
case class ErrorMessage(message: String, parameters: Any*) { | |
override def toString = message.format(parameters: _*) | |
} | |
case class Person(name: String, age: Int) |
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
// Example values. | |
val applyTitle = true | |
val title = Some("This is my Title!") | |
// We want to map these values to Option[Option[String]] | |
// where Option[String] is our value, and the outer Option[_] | |
// is an indicator on wether we should later use the value or not. | |
// | |
// eg: We want to support three use-cases: | |
// |
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 HomepagePresenter { | |
import newsroom.api | |
import TupleFutureUnzip._ | |
def apply(context: Context)(implicit ec: ExecutionContext): Future[HomepagePresenter] = { | |
// prepare all our futures since a for-comprehension would serialize our work (and that would be bad). | |
val future_Tree = ChanneledPresenter.tree | |
val future_Bulletin = api.bulletins.current |
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
libraryDependencies ++= { | |
CrossVersion.partialVersion(scalaVersion.value) match { | |
case Some((2, 11)) => commonDependencies ++ Seq( | |
"com.typesafe.scala-logging" %% "scala-logging-slf4j" % "2.1.1") | |
case _ => commonDependencies ++ Seq( | |
"com.typesafe" %% "scalalogging-slf4j" % "1.0.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
package com.github.sam.examples | |
object Quasiquotes extends App { | |
val universe = reflect.runtime.universe | |
import universe._ | |
import reflect.runtime.currentMirror | |
import scala.tools.reflect.ToolBox |
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
case class Foo(a: String, b: Int) | |
object Foo { | |
def apply(a: String, b: String) = new Foo(a, b.toInt) | |
} | |
val format = jsonFormat2[Foo](new { | |
def apply(a: String, b: Int): Foo = Foo(a, b) | |
def unapply(f: Foo) = Foo.unapply(f) |
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
// To Override or Not To Override (that is the question): | |
trait Foo { | |
def close: Unit | |
def bar(baz: String): Int | |
def zed(y: Int): Int = y * 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
// It seems like Props is a closure that gets reused? The first pass will work. | |
// The next will cause the BatchUpdate Actor to send deadLetters. As if the sender | |
// terminated prematurely. | |
query { | |
Rows(multiStoryQuery(revs.map(_._1)).list) | |
} pipeTo context.actorOf(Props(new BatchUpdate(context.sender(), revs)), s"batch-update-story-${Math.abs(Random.nextInt())}") | |
// This works however. So the problem actually seems to be that successive iterations of the above | |
// version go to the same (now stopped) passed sender. |
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 Lucene { | |
object Escape extends (String => String) { | |
private val prefix: Char => PartialFunction[Char, String] = c => { case `c` => s"\\$c" } | |
private val escapist: PartialFunction[Char, String] = prefix('\\') orElse | |
prefix('+') orElse | |
prefix('-') orElse | |
prefix('!') orElse |
OlderNewer