Skip to content

firaja/Jenerators

Repository files navigation

Jenerators

Build Status Maintainability codecov License

A Java library for building generators.

With a simple and clear interface, build a generator returning elements on-demand.

Getting Started

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)

Documentation

The javadoc API can be found in this page

Authors

  • David Bertoldi - Creator - firaja

See also the list of contributors who participated in this project.

License

This project is licensed under the Apache-2.0 - see the LICENSE file for details