Skip to content

Instantly share code, notes, and snippets.

@dylon
Created September 15, 2013 04:37
Show Gist options
  • Save dylon/6568068 to your computer and use it in GitHub Desktop.
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).
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