@NotNull
  private static <E extends ResolveResult> List<E> forEveryScopeTakeOverloadsOtherwiseImplementations(
    @NotNull List<E> elements,
    @NotNull Function<? super E, PsiElement> mapper,
    @NotNull TypeEvalContext context
  ) {
    if (!containsOverloadsAndImplementations(elements, mapper, context)) {
      return elements;
    }

    return StreamEx
      .of(elements)
      .groupingBy(element -> Optional.ofNullable(ScopeUtil.getScopeOwner(mapper.apply(element))), LinkedHashMap::new, Collectors.toList())
      .values()
      .stream()
      .flatMap(oneScopeElements -> takeOverloadsOtherwiseImplementations(oneScopeElements, mapper, context))
      .collect(Collectors.toList());
  }
@NotNull
  private static <E extends ResolveResult> List<E> forEveryScopeTakeOverloadsOtherwiseImplementations(
    @NotNull List<E> elements,
    @NotNull Function<? super E, PsiElement> mapper,
    @NotNull TypeEvalContext context
  )