A Java library for building generators.
With a simple and clear interface, build a generator returning elements on-demand.
The following code models the mathematical structure for the first 50 elements of the Fibonacci sequence:
StatefulGenerator<Long> fibonacci = new MemoryListGenerator<Long>(50) {
@Override
public Long generate() {
if (c() == 0) {
return 1L;
} else if (c() == 1) {
return 1L;
} else {
return getResult(c() - 1) + getResult(c() - 2);
}
}
};
And then you can just lazily retrieve the results like this:
for(Long i : fibonacci){
System.out.println(i);
}
(the n-th element of the Fibonacci sequence is calculated during the n-th iteration of the for loop)
The javadoc API can be found in this page
- David Bertoldi - Creator - firaja
See also the list of contributors who participated in this project.
This project is licensed under the Apache-2.0 - see the LICENSE file for details