Question: I need to generate stream of **integers** that each value is based on the value before according to some math function.

For example - lets say I want to take last number and add 10:
[1, 11, 21, 31, 41, ...]

of course the real function is much more complex.

I tried taking the fibonaci example but couldn't make it work:

```
Stream.iterate(new long[]{ 1, 1 }, p->new long[]{ p[1], p[0]+p[1] })
      .limit(92).forEach(p->System.out.println(p[0]));

```

I can only start at 1.

This is what I tried doing:

```
Stream.iterate(new long[]{ 1 }, p-> {p[0], p[0] + 10})
.limit(4).forEach(p->System.out.println(p[0]));

```

Answer: 
According to [`Stream#iterate`](https://docs.oracle.com/javase/8/docs/api/java/util/stream/Stream.html#iterate-T-java.util.function.UnaryOperator-) method docs:

> 
> Returns an infinite sequential ordered Stream produced by iterative application of a function f to an initial element seed, producing a Stream consisting of seed, f(seed), f(f(seed)), etc.
> 
> 
> The first element (position 0) in the Stream will be the provided seed. For n > 0, the element at position n, will be the result of applying the function f to the element at position n - 1.
> 
> 
> 

So, for your example, it should work as follows:

```
Stream.iterate(1L, x -> x + 10L)
    .limit(4)
    .forEach(System.out::println); // 1 11 21 31

```

If your function is too complex, you can abstract it to a method:

```
private long complexFunction(long value) {
    return <very_complex_calculation with value>;
}

long N = 4L;

Stream.iterate(1L, this::complexFunction)
    .limit(N)
    .forEach(System.out::println);

```
if I don't misunderstand you, you want something like this, you needn't any `long[]`array at all.

```
LongStream.iterate(1, it -> it + 10).limit(8).forEach(System.out::println);

```

for the `Integer`s you can using `IntStream#interate` instead:

```
//                         v--- call your math function here
IntStream.iterate(1, it -> math(it, ...)).limit(8).forEach(System.out::println);

```

**OR** using `LongStream#range` instead:

```
LongStream.range(0,8).map(it -> 10*it + 1).forEach(System.out::println);

```

Output
------

```
[1, 11, 21, 31, 41, 51, 61, 71]

```