package me.gurpreetsk.rxoperators.ui.transformation;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;
import me.gurpreetsk.rxoperators.R;

public class FlatmapActivity extends AppCompatActivity {

  @BindView(R.id.textview_flatmap)
  TextView textviewFlatmap;

  Disposable disposable;

  private static final String TAG = MapActivity.class.getSimpleName();

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_flatmap);
    ButterKnife.bind(this);
  }

  @Override
  protected void onStart() {
    super.onStart();

  }

  @Override
  protected void onStop() {
    super.onStop();
    // dispose off the used resources
    if (!disposable.isDisposed())
      disposable.dispose();
  }

}

@@ -1083,16 +1083,979 @@
 tart();%0A
+    disposable = Observable.just(2, 4, 6, 8, 10)%0A        .subscribeOn(Schedulers.io())%0A        .observeOn(Schedulers.io())%0A        // the flatmap operator does some processing on each element passed by the observable to it%0A        // and returns an *observable* for each element%0A        //(see https://stackoverflow.com/questions/22847105/when-do-you-use-map-vs-flatmap-in-rxjava)%0A        .flatMap(new Function%3CInteger, ObservableSource%3CInteger%3E%3E() %7B%0A          @Override%0A          public ObservableSource%3CInteger%3E apply(@NonNull Integer integer) throws Exception %7B%0A            return Observable.just(1, 2, 3);%0A          %7D%0A        %7D)%0A        .observeOn(AndroidSchedulers.mainThread())%0A        .subscribe(new Consumer%3CInteger%3E() %7B%0A          @Override%0A          public void accept(Integer integer) throws Exception %7B%0A            Log.i(TAG, %22accept: %22 + integer);%0A            textviewFlatmap.setText(textviewFlatmap.getText() + %22 %22 + integer);%0A          %7D%0A        %7D);
 %0A  %7D%0A%0A  

add FlatMap example