I'm trying to create a fibonacci sequence through the usage of Java Streams API. I've create a supplier, but I want it to stop at a specific value (e.g 1000000).
The suplier:
import java.util.function.Supplier;
public class FibonacciSupplier implements Supplier<Integer> {
private int current;
private int next;
public FibonacciSupplier() {
current = 0;
next = 1;
}
@Override
public Integer get() {
int result = current;
current = next + current;
next = result;
return result;
}
}
How I would like it to be:
Stream.generate(new FibonacciSupplier()).maxValue(1000000);
The maxValue does not exist as a function, I'm using it as a name to for context.