Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there no mapToInt() in the OptionalInt class?

Tags:

java

java-8

The IntStream class has map(), mapToObj(), mapToLong() and mapToDouble() methods, but those methods seem to be missing from the OptionalInt class.

Is there a good reason for those methods to be missing?

like image 568
TBieniek Avatar asked Jul 27 '15 12:07

TBieniek


1 Answers

Rather obtusely you can do

OptionalInt oi = OptionalInt.of(1);
oi.ifPresent(i -> IntStream.of(i).map(j -> j + 1).forEach(System.out::println));

However it is not clear why OptionalInt doesn't have the same methods as IntStream although I note Optional has a subset of Stream

like image 147
Peter Lawrey Avatar answered Nov 15 '22 12:11

Peter Lawrey