Skip to content

Instantly share code, notes, and snippets.

@harmeetsingh0013
Created July 7, 2018 11:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save harmeetsingh0013/dec68b81e4da99500c1f3c683e5be60e to your computer and use it in GitHub Desktop.
Save harmeetsingh0013/dec68b81e4da99500c1f3c683e5be60e to your computer and use it in GitHub Desktop.
object EvalExample1 extends App {
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