Have a function that returns a Set<> I want to apply that function over another collection, create a flattened Set<> below is the code snippet with map with just variables renamed
repository.findAll().stream().map(
p -> forecastService.forecast(p, timeLineInYear, label)
).collect(Collectors.toSet());
ForecastService returns Set<Forecast> so the above statement returns Set<Set<Forecast>>
when I try turning the same statement with a flatMap
repository.findAll().stream().flatMap(
p -> forecastService.forecast(p, timeLineInYear, label)
).collect(Collectors.toSet());
I get an compilation error
no instance of type variable R exist so that
Set<Forecast>conforms toStream<? extends R>
Appreciate any help.