https://github.com/firaja/jenerators
:electric_plug: A java library for generators
https://github.com/firaja/jenerators
generator java-generator java-generators java-library
Last synced: 7 months ago
JSON representation
:electric_plug: A java library for generators
- Host: GitHub
- URL: https://github.com/firaja/jenerators
- Owner: firaja
- License: apache-2.0
- Created: 2018-04-08T13:05:11.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-02-29T11:14:09.000Z (almost 6 years ago)
- Last Synced: 2025-03-12T17:18:03.542Z (10 months ago)
- Topics: generator, java-generator, java-generators, java-library
- Language: Java
- Homepage:
- Size: 366 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Jenerators
[](https://travis-ci.org/firaja/java-generators)
[](https://codeclimate.com/github/firaja/java-generators/maintainability)
[](https://codecov.io/gh/firaja/java-generators)
[](https://opensource.org/licenses/Apache-2.0)
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:
```java
StatefulGenerator fibonacci = new MemoryListGenerator(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:
```java
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](https://firaja.github.io/java-generators/doc)
## Authors
* **David Bertoldi** - *Creator* - [firaja](https://github.com/firaja)
See also the list of [contributors](https://github.com/firaja/java-generators/graphs/contributors) who participated in this project.
## License
This project is licensed under the Apache-2.0 - see the [LICENSE](LICENSE) file for details