public T withSmallestMappedDouble(Java7DoubleMapper<T> mapper) { if (used) { throw new RuntimeException("This stream has already been used."); } T smallest = null; for (T object : collection) { if (smallest == null || mapper.map(object) < mapper.map(smallest)) { smallest = object; } } return smallest; }
public Java7DoubleStream mapToDouble(Java7DoubleMapper<T> mapper) { if (used) { throw new RuntimeException("This stream has already been used."); } List<Double> newDoubleList = new ArrayList<>(); for (T object : collection) { newDoubleList.add(mapper.map(object)); } return Java7DoubleStream.doubleStream(newDoubleList); }