Last active
August 29, 2015 14:26
-
-
Save danieldietrich/95e92d9430b01d1019c1 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
/** | |
* This is a Java class using Javaslang's Lazy | |
*/ | |
class LazyDemo {{ | |
// -- Lazy instance | |
Lazy<String> value = Lazy.of(() -> "Yay!"); | |
value.toString(); // = Lazy(?) | |
value.get(); // = "Yay!" | |
value.toString(); // = "Lazy(Yay!) | |
// -- lazy value | |
// chars is a CharSequence Proxy backed by a Lazy | |
CharSequence chars = Lazy.asVal(() -> "Yay!", CharSequence.class); | |
// = "Yay!" (lazily evaluated) | |
chars.toString(); | |
}} |
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
# | |
# This is just a comparison to Scala's behavior | |
# | |
scala> lazy val s = "Yay!" | |
s: String = <lazy> | |
scala> println(s) | |
Yay! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment