Forked from harmeetsingh0013/EvalExample1.scala
Last active
October 26, 2018 11:29
-
-
Save rm--/463978126aa4a6f88a1142f6f18f3714 to your computer and use it in GitHub Desktop.
scratch file
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 cats._ | |
val eager = Eval.now { | |
println("Hey !! I am eager eval") | |
"Hello Eval Eager" | |
} | |
val lazyEval = Eval.later { | |
println("Hey !! I am lazy eval") | |
"Hello Eval Lazy" | |
} | |
val always = Eval.always { | |
println("Hey !! I am always eval") | |
"Hello Eval Always" | |
} | |
println(s"Eval Eager: ${eager}") | |
println(s"Eval Eager 1: ${eager.value}") | |
println(s"Eval Eager 2: ${eager.value}") | |
println(s"Eval Lazy: ${lazyEval}") | |
println(s"Eval Lazy 1: ${lazyEval.value}") | |
println(s"Eval Lazy 2: ${lazyEval.value}") | |
println(s"Eval Always: ${always}") | |
println(s"Eval Always 1: ${always.value}") | |
println(s"Eval Always 2: ${always.value}") | |
/* OUTPUT | |
Hey !! I am eager eval | |
Eval Eager: Now(Hello Eval Eager) | |
Eval Eager 1: Hello Eval Eager | |
Eval Eager 2: Hello Eval Eager | |
Eval Lazy: cats.Later@61a485d2 | |
Hey !! I am lazy eval | |
Eval Lazy 1: Hello Eval Lazy | |
Eval Lazy 2: Hello Eval Lazy | |
Eval Always: cats.Always@39fb3ab6 | |
Hey !! I am always eval | |
Eval Always 1: Hello Eval Always | |
Hey !! I am always eval | |
Eval Always 2: Hello Eval Always | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment