private List<BaseIcon> filterIconsToChangeByPositions(List<BaseIcon> baseIcons, List<Integer> positions) { return baseIcons.stream() .filter(baseIcon -> pred(positions)) .collect(Collectors.toList()); } private Predicate<BaseIcon> pred(List<Integer> positions) { return baseIcon -> positions.stream().anyMatch(pos -> pos == baseIcon.getPositionOnGameField()); } 

I can not understand why the data does not compile, since the type says that the lmbd has a bad type

    1 answer 1

    You write another lambda calling your function in the filter. Just pass it on to it.

     .filter(pred(positions)) 
    • After all, filter accepts a predicate, and the pred function just gives it away, because this is the same as filter (baseIcon -> positions.stream (). AnyMatch (pos -> pos == baseIcon.getPositionOnGameField ())) - Vladimir
    • This is what the full version of your function looks like in the filter: .filter((baseIcon) -> {return pred(positions);}) filter expects that it will be given a function returning a boolean value. And you give him another lambda instead. To call a function that you return from pred , you need to call its functional interface method: .filter(baseIcon -> pred(positions).test(baseIcon)) - user320999