title: Flattening a List with RxJava
body: <p>I am trying to convert flatten a List using Rx. Heres the current code:</p>
  
  <pre><code>rxflatten(treeList).subscribe(new Action1&lt;List&lt;Object&gt;&gt;() {
              @Override
              public void call(List&lt;Object&gt; objects) {
                  Log.d("test", "original= " + treeList + " flattened=" + objects) ;
              }
          });
  
  
  public static Observable&lt;Object&gt; rxflattenmylist(List&lt;?&gt; list) {
         return Observable.from(list)
                  .flatMap(item -&gt; item instanceof List&lt;?&gt; ? rxflattenmylist((List&lt;?&gt;) item) : Observable.just(item));
      }
  
   public static Observable&lt;List&lt;Object&gt;&gt; rxflatten(List&lt;?&gt; list) {
          return rxflattenmylist(list)
                  .toList();
  
      }
  </code></pre>
  
  <p>This is the first data set</p>
  
  <pre><code>private static List&lt;Object&gt; a(Object... a) {
          return Arrays.asList(a);
      }
  
  List&lt;Object&gt; treeList = a(a(1), 2, a(a(3, 4), 5), a(a(a())), a(a(a(6))), 7, 8, a());
  </code></pre>
  
  <p>Using this dataset, the following output is produced:</p>
  
  <blockquote>
    <p>original= [[1], 2, [[3, 4], 5], [[[]]], [[[6]]], 7, 8, []] flattened=[1, 2, 3, 4, 5, 6, 7, 8]</p>
  </blockquote>
  
  <p>Here is a second dataset</p>
  
  <pre><code>private Object[] mNestedArrays = new Object[] {
              new Object[] { new Integer[] { 1, 2 }, new Integer[] { 3, 4 }},
              new Integer[] { 5, 6 }
      };
  
   List&lt;Object&gt; treeList = Arrays.asList(mNestedArrays);
  </code></pre>
  
  <p>I was trying to do the same using the above dataset, but instead of flattening, it only emits the top 2 items (an Object and Integer array).</p>
  
  <p>Here is the output for this dataset:</p>
  
  <blockquote>
    <p>original= [Ljava.lang.Object; flattened=[[Ljava.lang.Object;, [Ljava.lang.Integer;]</p>
  </blockquote>
  
  <p>So how would I flatten the second dataset using RxJava? </p>
  
  <p>Thanks!</p>