In Java8 streams I can use the mapToInt
method to create an IntStream
, which will return OptionalInt
s for some actions (like findFirst
). Why isn't there anything similar in Optional
?
int i = Stream
.of("1") // just as an example
.mapToInt(Integer::parseInt) // mapToInt exists for streams
.findFirst() // this even returns an OptionalInt!
.getAsInt(); // quite handy
int j = Optional
.of("1") // same example
.map(Integer::parseInt) // no mapToInt available
.get().intValue(); // not as handy as for streams