rx.Observable.from()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(231)

本文整理了Java中rx.Observable.from()方法的一些代码示例,展示了Observable.from()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.from()方法的具体详情如下:
包路径:rx.Observable
类名称:Observable
方法名:from

Observable.from介绍

[英]Converts an Iterable sequence into an Observable that emits the items in the sequence.

Scheduler: from does not operate by default on a particular Scheduler.
[中]将可观测序列转换为可观测序列,并发射序列中的项目。
调度程序:默认情况下,from不会在特定调度程序上运行。

代码示例

代码示例来源:origin: Rukey7/MvpApp

@Override
  public Observable<NewsInfo> call(Map<String, List<NewsInfo>> newsListMap) {
    return Observable.from(newsListMap.get(typeStr));
  }
};

代码示例来源:origin: Rukey7/MvpApp

@Override
  public Observable<T> call(Map<String, List<T>> stringListMap) {
    if (TextUtils.isEmpty(mMapKey)) {
      return Observable.error(new Throwable("Map Key is empty"));
    }
    return Observable.from(stringListMap.get(mMapKey));
  }
}).subscribeOn(Schedulers.io())

代码示例来源:origin: Netflix/conductor

@Override
public Observable<Message> observe() {
  return Observable.from(messages);
}

代码示例来源:origin: RichardWarburton/java-8-lambdas-exercises

private Observable<Artist> lookupArtist(String name) {
  Artist required = savedArtists.stream()
                 .filter(artist -> artist.getName().equals(name))
                 .findFirst()
                 .get();
  return Observable.from(required);
}

代码示例来源:origin: PipelineAI/pipeline

@Override
  protected Observable<Pair<String, Integer>> construct() {
    return Observable.from(args).map(new Func1<String, Pair<String, Integer>>() {
      @Override
      public Pair<String, Integer> call(String s) {
        return new Pair<String, Integer>(s, Integer.parseInt(s));
      }
    });
  }
}

代码示例来源:origin: Netflix/conductor

@VisibleForTesting
  private OnSubscribe<Message> getOnSubscribe() {
    return subscriber -> {
      Observable<Long> interval = Observable.interval(pollTimeInMS, TimeUnit.MILLISECONDS);
      interval.flatMap((Long x) -> {
        List<Message> msgs = receiveMessages();
        return Observable.from(msgs);
      }).subscribe(subscriber::onNext, subscriber::onError);
    };
  }
}

代码示例来源:origin: Netflix/conductor

@VisibleForTesting
OnSubscribe<Message> getOnSubscribe() {
  return subscriber -> {
    Observable<Long> interval = Observable.interval(pollTimeInMS, TimeUnit.MILLISECONDS);
    interval.flatMap((Long x)->{
      List<Message> msgs = receiveMessages();
      return Observable.from(msgs);
    }).subscribe(subscriber::onNext, subscriber::onError);
  };
}

代码示例来源:origin: grandcentrix/tray

private List<String> getNiceString(final Collection<TrayItem> items) {
  return Observable.from(items)
      .map(new Func1<TrayItem, String>() {
        @Override
        public String call(final TrayItem trayItem) {
          return "key: '" + trayItem.key() + "' value '" + trayItem.value() + "'";
        }
      })
      .toList().toBlocking().first();
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

private void initFragments() {
 fragments.add(RegionTypeRecommendFragment.newInstance(rid));
 Observable.from(childrens)
   .subscribe(childrenBean -> fragments.add(RegionTypeDetailsFragment.
     newInstance(childrenBean.getTid())));
}

代码示例来源:origin: ReactiveX/RxNetty

private Observable<ByteBuf> toByteBufObservable(String... values) {
  return Observable.from(values)
      .map(new Func1<String, ByteBuf>() {
        @Override
        public ByteBuf call(String s) {
          return getByteBuf(s);
        }
      });
}

代码示例来源:origin: Rukey7/MvpApp

@Override
  public Observable<WelfarePhotoInfo> call(WelfarePhotoList welfarePhotoList) {
    if (welfarePhotoList.getResults().size() == 0) {
      return Observable.empty();
    }
    return Observable.from(welfarePhotoList.getResults());
  }
};

代码示例来源:origin: ReactiveX/RxNetty

public static Observable<ByteBuf> bbJust(String... items) {
  List<ByteBuf> bbItems = new ArrayList<>();
  for (String item : items) {
    bbItems.add(Unpooled.buffer().writeBytes(item.getBytes()));
  }
  return Observable.from(bbItems);
}

代码示例来源:origin: alipay/sofa-rpc

@Override
protected Observable construct() {
  this.sofaResponse = invoker.invoke(request);
  this.responseFuture = RpcInternalContext.getContext().getFuture();
  return Observable.from(this.responseFuture);
}

代码示例来源:origin: alipay/sofa-rpc

@Override
protected Observable construct() {
  this.sofaResponse = invoker.invoke(request);
  this.responseFuture = RpcInternalContext.getContext().getFuture();
  return Observable.from(this.responseFuture);
}

代码示例来源:origin: spring-projects/spring-framework

@Test
public void rxObservableToPublisher() {
  List<Integer> sequence = Arrays.asList(1, 2, 3);
  Object source = rx.Observable.from(sequence);
  Object target = getAdapter(rx.Observable.class).toPublisher(source);
  assertTrue("Expected Flux Publisher: " + target.getClass().getName(), target instanceof Flux);
  assertEquals(sequence, ((Flux<Integer>) target).collectList().block(Duration.ofMillis(1000)));
}

代码示例来源:origin: apache/usergrid

@Test
public void testSubscribe(){
  List<Integer> expected = Arrays.asList( 10, 9, 9,  8, 7, 6,  6, 5, 5, 5, 4, 3, 3, 2, 2, 1, 1, 0);
  final AtomicInteger i = new AtomicInteger();
  Observable.from(expected).doOnNext(x -> {
    logger.info("print " + x);
    i.set(x);
  }).doOnError(e -> logger.error(e.getMessage())).subscribe();
  logger.info("last");
  assertTrue(i.get()==0);
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

/**
 * 设置轮播banners
 */
private void convertBanner() {
  Observable.from(recommendBanners)
      .compose(bindToLifecycle())
      .forEach(dataBean -> banners.add(new BannerEntity(dataBean.getValue(),
          dataBean.getTitle(), dataBean.getImage())));
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

private void setBanner() {
  Observable.from(banners)
      .compose(bindToLifecycle())
      .forEach(topBean -> bannerEntities.add(new BannerEntity(
          topBean.getUri(), topBean.getTitle(), topBean.getImage())));
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

private void setBanner() {
  Observable.from(banners)
      .compose(bindToLifecycle())
      .forEach(topBean -> bannerEntities.add(new BannerEntity(topBean.getUri(),
          topBean.getTitle(), topBean.getImage())));
}

代码示例来源:origin: HotBitmapGG/bilibili-android-client

@Override
public void finishTask() {
  Observable.from(results)
      .compose(bindToLifecycle())
      .forEach(resultBean -> mSectionedRecyclerViewAdapter.addSection(
          new SeasonNewBangumiSection(SeasonNewBangumiActivity.this,
              resultBean.getSeason(), resultBean.getYear(), resultBean.getList())));
  mSectionedRecyclerViewAdapter.notifyDataSetChanged();
  hideProgressBar();
}

相关文章

Observable类方法