content: package com.rxjava2.android.samples.ui.operators;
  
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.widget.Button;
  import android.widget.TextView;
  
  import com.rxjava2.android.samples.R;
  import com.rxjava2.android.samples.model.ApiUser;
  import com.rxjava2.android.samples.model.User;
  import com.rxjava2.android.samples.utils.AppConstant;
  import com.rxjava2.android.samples.utils.Utils;
  
  import java.util.List;
  
  import androidx.appcompat.app.AppCompatActivity;
  import io.reactivex.Observable;
  import io.reactivex.ObservableEmitter;
  import io.reactivex.ObservableOnSubscribe;
  import io.reactivex.Observer;
  import io.reactivex.android.schedulers.AndroidSchedulers;
  import io.reactivex.disposables.Disposable;
  import io.reactivex.functions.Function;
  import io.reactivex.schedulers.Schedulers;
  
  /**
   * Created by amitshekhar on 27/08/16.
   */
  public class MapExampleActivity extends AppCompatActivity {
  
      private static final String TAG = MapExampleActivity.class.getSimpleName();
      Button btn;
      TextView textView;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_example);
          btn = findViewById(R.id.btn);
          textView = findViewById(R.id.textView);
  
          btn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  doSomeWork();
              }
          });
      }
  
      /*
      * Here we are getting ApiUser Object from api server
      * then we are converting it into User Object because
      * may be our database support User Not ApiUser Object
      * Here we are using Map Operator to do that
      */
      private void doSomeWork() {
          getObservable()
                  // Run on a background thread
                  .subscribeOn(Schedulers.io())
                  // Be notified on the main thread
                  .observeOn(AndroidSchedulers.mainThread())
                  .map(new Function<List<ApiUser>, List<User>>() {
  
                      @Override
                      public List<User> apply(List<ApiUser> apiUsers) {
                          return Utils.convertApiUserListToUserList(apiUsers);
                      }
                  })
                  .subscribe(getObserver());
      }
  
      private Observable<List<ApiUser>> getObservable() {
          return Observable.create(new ObservableOnSubscribe<List<ApiUser>>() {
              @Override
              public void subscribe(ObservableEmitter<List<ApiUser>> e) {
                  if (!e.isDisposed()) {
                      e.onNext(Utils.getApiUserList());
                      e.onComplete();
                  }
              }
          });
      }
  
      private Observer<List<User>> getObserver() {
          return new Observer<List<User>>() {
  
              @Override
              public void onSubscribe(Disposable d) {
                  Log.d(TAG, " onSubscribe : " + d.isDisposed());
              }
  
              @Override
              public void onNext(List<User> userList) {
                  textView.append(" onNext");
                  textView.append(AppConstant.LINE_SEPARATOR);
                  for (User user : userList) {
                      textView.append(" firstname : " + user.firstname);
                      textView.append(AppConstant.LINE_SEPARATOR);
                  }
                  Log.d(TAG, " onNext : " + userList.size());
              }
  
              @Override
              public void onError(Throwable e) {
                  textView.append(" onError : " + e.getMessage());
                  textView.append(AppConstant.LINE_SEPARATOR);
                  Log.d(TAG, " onError : " + e.getMessage());
              }
  
              @Override
              public void onComplete() {
                  textView.append(" onComplete");
                  textView.append(AppConstant.LINE_SEPARATOR);
                  Log.d(TAG, " onComplete");
              }
          };
      }
  
  
  }