Created
September 15, 2013 04:37
-
-
Save dylon/6568068 to your computer and use it in GitHub Desktop.
Demonstrates how to use lombok-pg 0.11.3's yield statement to create a generator function (i.e. lazy sequence).
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
import static lombok.Yield.yield; | |
public class YieldTest { | |
public static void main(final String... args) { | |
for (int i : evens()) { | |
System.out.println(i); | |
} | |
} | |
private static Iterable<Integer> evens() { | |
for (int i = Integer.MIN_VALUE; i < Integer.MAX_VALUE; i += 2) { | |
yield(i); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment