Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

convert to lambda from rx java expression

I've started to grok into retrolambda and rxjava. Some expressions i'v converted by myself, but some of them i can't convert. I've added retrolambda to my project.Here is examples

public Observable<ImmutableList<Repository>> getUsersRepositories() {
        return githubApiService.getUsersRepositories(user.login)
                .map(repositoryResponses -> {
                        final ImmutableList.Builder<Repository> listBuilder = ImmutableList.builder();
                        for (RepositoryResponse repositoryResponse : repositoryResponses) {
                            Repository repository = new Repository();
                            repository.id = repositoryResponse.id;
                            repository.name = repositoryResponse.name;
                            repository.url = repositoryResponse.url;
                            listBuilder.add(repository);
                        }
                        return listBuilder.build();
                })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread());
    }

But i don't know how to convert this peace of code:

obs.subscribe(new Observer<List<Integer>>() {
        public void onCompleted() {
            System.out.println("completed");
        }

        public void onError(Throwable e) {
            System.out.println("failure");
        }

        public void onNext(List<Integer> value) {
            System.out.println("onnext=" + value);
        }
    });
like image 301
Jenya Kirmiza Avatar asked Feb 09 '23 05:02

Jenya Kirmiza


1 Answers

I think that you want to make something like this:

obs.subscribe(
         (List<Integer> value) -> System.out.println("onnext=" + value),
         (Throwable e) -> System.out.println("failure"),
         ()-> System.out.println("completed"));

You can check this blog and this example in GitHub.

like image 65
Cabezas Avatar answered Feb 24 '23 19:02

Cabezas