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

Compose generics without Transformer #1770

Closed
wants to merge 1 commit into from

Conversation

vadims
Copy link
Contributor

@vadims vadims commented Oct 16, 2014

No description provided.

@benjchristensen
Copy link
Member

The test failure is a known non-deterministic test.

@benjchristensen
Copy link
Member

This change forces this code:

public static void main(String[] args) {
        List<Movie> list1 = Arrays.asList(new Movie(), new HorrorMovie(), new ActionMovie());
        List<Movie> list2 = Arrays.asList(new ActionMovie(), new Movie(), new HorrorMovie(), new ActionMovie());
        Observable<List<Movie>> movies = Observable.just(list1, list2);
        Observable<Movie> compose = movies.compose(ComposeExample2::transform);
        compose.subscribe(System.out::println);
    }

    public static Observable<Movie> transform(Observable<List<Movie>> movieList) {
        return movieList
                .startWith(new ArrayList<Movie>())
                .buffer(2, 1)
                .skip(1)
                .flatMap(ComposeExample2::calculateDelta);
    }

    public static Observable<Movie> calculateDelta(List<List<Movie>> listOfLists) {
        if (listOfLists.size() == 1) {
            return Observable.from(listOfLists.get(0));
        } else {
            // diff the two
            List<Movie> newList = listOfLists.get(1);
            List<Movie> oldList = new ArrayList<Movie>(listOfLists.get(0));

            Set<Movie> delta = new LinkedHashSet<Movie>();
            delta.addAll(newList);
            // remove all that match in old
            delta.removeAll(oldList);

            // filter oldList to those that aren't in the newList
            oldList.removeAll(newList);

            // for all left in the oldList we'll create DROP events
            for (Movie old : oldList) {
                delta.add(new Movie());
            }

            return Observable.from(delta);
        }
    };

to something that is awkward enough I gave up after a few minutes to try and make it work:

public static Observable<? extends Movie> transform(Observable<? super List<Movie>> movieList) {
        return movieList
                .startWith(new ArrayList<Movie>())
                .buffer(2, 1)
                .skip(1)
                .flatMap(ComposeExample2::calculateDelta);
    }

    public static Observable<Movie> calculateDelta(List<? super List<Movie>> listOfLists) {
... all breaks here ...
    }

screen shot 2014-10-16 at 9 09 17 am

I really don't like when we need signatures like List<? super List<Movie>>.

@vadims
Copy link
Contributor Author

vadims commented Oct 16, 2014

After playing with it some more, I don't think that Transformer can be removed

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

Successfully merging this pull request may close these issues.

2 participants