Skip to content

Instantly share code, notes, and snippets.

@abner
Last active January 18, 2018 01:46
Show Gist options
  • Select an option

  • Save abner/247e640d0360e8b717e5e47385d046ba to your computer and use it in GitHub Desktop.

Select an option

Save abner/247e640d0360e8b717e5e47385d046ba to your computer and use it in GitHub Desktop.

Revisions

  1. abner revised this gist Jan 17, 2018. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion ArrayToSingleResult.java
    Original file line number Diff line number Diff line change
    @@ -10,6 +10,8 @@ public class RxPlayground {
    public static void main(String[] args) {

    JsonArray jsonArray = new JsonArray().add(1).add(2).add(3);

    // toList => See http://tomstechnicalblog.blogspot.com.br/2015/11/rxjava-operators-tolist.html
    Object b = Observable
    .from(jsonArray.getList().toArray())
    .switchMap(x ->
    @@ -22,7 +24,7 @@ public static void main(String[] args) {
    ((Single) b).subscribe(System.out::println);
    System.out.println(b);


    // Here, using Buffer operator
    Object c = Observable
    .from(jsonArray.getList().toArray())
    .switchMap(x ->
  2. abner created this gist Jan 17, 2018.
    44 changes: 44 additions & 0 deletions ArrayToSingleResult.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    import io.vertx.core.json.JsonArray;
    import rx.Observable;
    import rx.Single;

    /**
    * @author abner2
    */
    public class RxPlayground {

    public static void main(String[] args) {

    JsonArray jsonArray = new JsonArray().add(1).add(2).add(3);
    Object b = Observable
    .from(jsonArray.getList().toArray())
    .switchMap(x ->
    doSome((Integer) x).toObservable()
    )
    .toList()
    .toSingle()
    ;

    ((Single) b).subscribe(System.out::println);
    System.out.println(b);


    Object c = Observable
    .from(jsonArray.getList().toArray())
    .switchMap(x ->
    doSome((Integer) x).toObservable()
    )
    .buffer(jsonArray.size())
    .toSingle()
    ;

    ((Single) c).subscribe(System.out::println);
    System.out.println(c);

    }

    public static Single<String> doSome(Integer ind) {
    return Single.just(new Integer(ind + 1).toString());
    }

    }