将表达式转换为lambda

时间:2016-05-19 13:24:22

标签: lambda rx-java observable subscribe throwable

任何人都可以帮我将这段代码转换成lambda表达式, 我很震惊这个

Observable.create(new OnSubscribe<User>() {
        @Override
        public void call(Subscriber<? super User> arg0) {
            User updatedUser = userService.updateuser(usermapper.userdtotoentity(user));
            arg0.onNext(updatedUser);
        }
    }).subscribe(new Action1<User>() {
        @Override
        public void call(User user) {
            if (user != null) {
                response.resume(user);
            } else
                response.resume(Response.status(Status.NOT_FOUND).build());
        }
    }, new Action1<Throwable>() {
        @Override
        public void call(Throwable t) {
            logger.debug("User with email_id:" + email_id + " is not present");
            response.resume(t);
        }
    });

1 个答案:

答案 0 :(得分:3)

    Observable.<User>create(subscriber -> {

        User updatedUser = userService.updateuser(usermapper.userdtotoentity(user));
        subscriber.onNext(updatedUser);

    }).subscribe(

         user -> {
           if (user != null) {
              response.resume(user);
          } else {
            response.resume(Response.status(Status.NOT_FOUND).build());
          }
        }, 

         error -> {
            logger.debug("User with email_id:" + email_id + " is not present");
            response.resume(error);
         }
   );