Created
December 3, 2014 16:14
-
-
Save noelmarkham/9232cad55de53c4cfbd6 to your computer and use it in GitHub Desktop.
Questionable use of Scalaz Memo
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
object FlakyFunctionTest { | |
import scalaz._ | |
import Scalaz._ | |
var state = false | |
val function: Unit => String = scalaz.Memo.immutableHashMapMemo { _ => | |
println(s"We received a call") | |
if(!state) { | |
state = true | |
throw new RuntimeException("Oops, try again later") | |
} | |
s"Returning from this method" | |
} | |
} | |
scala> FlakyFunctionTest.function(()) | |
We received a call | |
java.lang.RuntimeException: Oops, try again later | |
at MemoTest$$anonfun$1.apply(<console>:39) | |
at MemoTest$$anonfun$1.apply(<console>:34) | |
at scalaz.MemoFunctions$$anonfun$immutableMapMemo$1$$anonfun$apply$4$$anonfun$apply$5.apply(Memo.scala:89) | |
at scala.Option.getOrElse(Option.scala:120) | |
at scalaz.MemoFunctions$$anonfun$immutableMapMemo$1$$anonfun$apply$4.apply(Memo.scala:88) | |
... 43 elided | |
scala> FlakyFunctionTest.function(()) | |
We received a call | |
res57: String = Returning from this method | |
scala> FlakyFunctionTest.function(()) | |
res58: String = Returning from this method |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment