-
-
Save evantill/4944402 to your computer and use it in GitHub Desktop.
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
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