Skip to content

Instantly share code, notes, and snippets.

@evantill
Forked from jeantil/implicits.scala
Last active December 13, 2015 16:59
Show Gist options
  • Save evantill/4944402 to your computer and use it in GitHub Desktop.
Save evantill/4944402 to your computer and use it in GitHub Desktop.
import collection.mutable
import org.specs2.mutable._
class ImplicitiSpec extends Specification {
type Store=Map[String,String]
object Value {
val store = new mutable.HashMap[String,String] with mutable.SynchronizedMap[String,String]
def apply(k:String)(implicit map:Store):String=store.getOrElseUpdate(k,applyWithoutLazy(k))
def applyWithoutLazy(k:String)(implicit map:Store):String={
println(s"reads value for ${k}")
map.get(k).getOrElse("")
}
}
trait A{
def a(implicit store:Store) = Value("a")
}
object B extends A
"An Implicit" should {
"be propagated " in{
implicit val m=Map("a"->"aa")
B.a === "aa"
B.a === "aa"
B.a === "aa"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment