Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] edge-SNAPSHOT fails to resolve a transformation extension method #2451

Closed
jm98 opened this issue May 4, 2020 · 1 comment
Closed

Comments

@jm98
Copy link

jm98 commented May 4, 2020

Describe the bug
A transformation extension method works in IntelliJ but not in Eclipse.
Eclipse reports:
The method select(Iterator<S>, Function<S,T>) in the type IteratorExtensionMethods is not applicable for the arguments (Iterator<String>)

This is a fundamental part of functional programming covering immutable, deterministic behaviour having no externally visible side affects.

Is this related to #1441

To Reproduce
Calling code:

List<String> list = Arrays.asList("Fred", "Jane", "Joe");
list
.iterator()
.select(s -> s.length())
.forEachRemaining(System.out::println);

calling .skip(2) works but calling .where(s -> s != null) does not

Extension method's class

import lombok.experimental.ExtensionMethod;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;

@ExtensionMethod({IteratorExtensionMethods.class})
public class IteratorExtensionMethods {
    public static <S, T> Iterator<T> select(
            Iterator<S> source,
            Function<S, T> projectionFunction) {

        return new Iterator<T>() {
            private final Iterator<S> sourceCollection = source;
            private final Function<S, T> transform = projectionFunction;

            public boolean hasNext() {
                return sourceCollection.hasNext();
            }

            public T next() {
                return this.transform.apply(sourceCollection.next());
            }
        };
    }
   
 public static <T> Iterator<T> skip(
            Iterator<T> source,
            int skipCount
    ) {
                return new Iterator<T>() {
            private int idx = skipCount < 0 ? 0 : skipCount;
            private final Iterator<T> iteratorSource = source;

            public boolean hasNext() {
                while (this.idx > 0 && this.iteratorSource.hasNext()) {
                    this.iteratorSource.next();
                    this.idx--;
                }
                return this.iteratorSource.hasNext();
            }

            public T next() {
                return this.iteratorSource.next();
            }
        };
    }

    public static <T> Iterator<T> where(
            Iterator<T> source,
            Predicate<T> predicate
    ) {
        return new Iterator<T>() {
            private final Iterator<T> iteratorWhereSource = source;
            private final Predicate<T> iteratorWherePredicate = predicate;
            private T current = null;

            public boolean hasNext() {
                while (this.iteratorWhereSource.hasNext()) {
                    this.current = this.iteratorWhereSource.next();
                    if (this.iteratorWherePredicate.test(current)) return true;
                }
                return false;
            }

            public T next() {
                return this.current;
            }
        };
    }

}

Expected behavior
4, 4, 3 should be written to console

Version info (please complete the following information):

  • Lombok edge-SNAPSHOT
  • Platform Eclipse 2020-03 (4.15.0) JRE 1.8.0_231
@Rawi01
Copy link
Collaborator

Rawi01 commented May 4, 2020

This is a duplicate of #1148 and fixed in #2413

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants