I think this question is useless, but i can`t find how i can union this code to one line
I have List of active Couriers. I am trying to find all free couriers in this list and after that find courier with min distance
List<Courier> afterCheckIsFree = activeCouriers.stream().filter(Courier::isFree).collect(Collectors.toList());
final Optional<Courier> courierWithMinDistance = afterCheckIsFree.stream()
.filter(n -> n.getId().equals(CourierFinder.minDistanceUsingCourier(Point.ZERO_POINT, afterCheckIsFree).getId())).findFirst();
Thanks a lot!
You should apply 2 criterias on your stream: firstly, checking if courier is free, secondly, sort remaining couriers by distance and take first. It will look like: