Stream "on the fly" from matrix I want to produce a Stream&lt;Pixel&gt; from a Pixel[][]. My code for this is extremely verbose so I suspect I am doing something bad.

Please provide me some advice on how to make my code shorter and cleaner.

private Stream&lt;Pixel&gt; stream() {
    Iterable&lt;Pixel&gt; iterable = new Iterable&lt;Pixel&gt;() {
        @Override
        public Iterator&lt;Pixel&gt; iterator() {
            return new Iterator&lt;Pixel&gt;() {
                private int row = 0;
                private int col = 0;

                @Override
                public boolean hasNext() {
                    return row &lt; height &amp;&amp; col &lt; width;
                }

                @Override
                public Pixel next() {
                    Pixel pixel = pixels[row][col];

                    if (col == width - 1) {
                        col = 0;
                        row++;
                    } else {
                        col++;
                    }

                    return pixel;
                }

                @Override
                public void remove() {
                    throw new RuntimeException("nope");
                }
            };
        }
    };

    return StreamSupport.stream(iterable.spliterator(), false);
}


For example, in Python I could do something like:

def stream():
    for row in pixels:
        for pixel in row:
            yield pixel


Which is certainly much more concise and understandable.
You can of course use the Arrays.stream() (twice, because it's a 2D array)

Something along these lines: 

private Stream&lt;Pixel&gt; stream() {
  return Arrays.stream(pixels).flatMap(Arrays::stream);
}