@Test public void testCollapseTemperatures() { WeatherService service = new WeatherService(new WeatherRestfullApi()); Stream<Location> locals = service.search("oporto"); Stream<Integer> temps = locals .skip(1) .findFirst() .get() .getPast30daysWeather() .map(WeatherInfo::getTempC); temps = StreamUtil.collapse(temps); String res = temps .map(Object::toString) .collect(Collectors.joining(",")); String expected = "16,13,14,12,11,14,19,16,18,15,14,17,21,19,14,17,19,21,22,20,22,23,21,24,25,21,20,18"; assertEquals(expected, res); }
public Stream<Location> search(String query) { Stream<LocationInfo> locals = api.search(query); return locals.map(this::toLocation); }
WeatherService { public Stream<Location> search(String query) { Stream<LocationInfo> locals = api.search(query); return locals.map(this::toLocation); } }
WeatherService { public Stream<Location> search(String query) { Stream<LocationInfo> locals = api.search(query); return locals.map(this::toLocation); } WeatherService(WeatherApi api);  WeatherService(); }
WeatherService { public Stream<Location> search(String query) { Stream<LocationInfo> locals = api.search(query); return locals.map(this::toLocation); } WeatherService(WeatherApi api);  WeatherService(); Stream<Location> search(String query); }
WeatherService { public Stream<Location> search(String query) { Stream<LocationInfo> locals = api.search(query); return locals.map(this::toLocation); } WeatherService(WeatherApi api);  WeatherService(); Stream<Location> search(String query);  }