I have the following piece of code, that I want to translate using Java 8 stream API.

```
count = 0;
for (A a : someList) {
   if (a.get() == 1) {
     count++;
     newList.add(new X(count));
   }
}

```

How can I get that count when mapping?

```
newList = someList.stream
.filter(a -> a.get().equals("red"))
.map(a -> new X(count))
.collect(Collectors.toList());

```