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

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

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

Observable.flatMap介绍

[英]Returns an Observable that emits items based on applying a function that you supply to each item emitted by the source Observable, where that function returns an Observable, and then merging those resulting Observables and emitting the results of this merger.

Scheduler: flatMap does not operate by default on a particular Scheduler.
[中]返回一个可观测项,该可观测项基于对源可观测项发出的每个项应用一个函数,该函数返回一个可观测项,然后合并这些结果可观测项并发出此合并的结果。
调度程序:默认情况下,flatMap不会在特定调度程序上运行。

代码示例

代码示例来源:origin: hidroh/materialistic

  1. @Override
  2. public void parse(String itemId, String url, Callback callback) {
  3. Observable.defer(() -> fromCache(itemId))
  4. .subscribeOn(mIoScheduler)
  5. .flatMap(content -> content != null ?
  6. Observable.just(content) : fromNetwork(itemId, url))
  7. .map(content -> AndroidUtils.TextUtils.equals(EMPTY_CONTENT, content) ? null : content)
  8. .observeOn(mMainThreadScheduler)
  9. .subscribe(callback::onResponse);
  10. }

代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources

  1. throw new IllegalArgumentException("Parameter parameters is required and cannot be null.");
  2. Validator.validate(parameters);
  3. final String apiVersion = "2017-06-01-preview";
  4. return service.createOrUpdateAtManagementGroup(policySetDefinitionName, managementGroupId, parameters, apiVersion, this.client.acceptLanguage(), this.client.userAgent())
  5. .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<PolicySetDefinitionInner>>>() {
  6. @Override
  7. public Observable<ServiceResponse<PolicySetDefinitionInner>> call(Response<ResponseBody> response) {

代码示例来源:origin: Azure/azure-libraries-for-java

  1. throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
  2. Validator.validate(parameters);
  3. final String op = "GRANTACE";
  4. String parameterizedHost = Joiner.on(", ").join("{accountName}", accountName, "{adlaCatalogDnsSuffix}", this.client.adlaCatalogDnsSuffix());
  5. return service.grantAclToDatabase(databaseName, parameters, op, this.client.apiVersion(), this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
  6. .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Void>>>() {
  7. @Override
  8. public Observable<ServiceResponse<Void>> call(Response<ResponseBody> response) {

代码示例来源:origin: Azure/azure-libraries-for-java

  1. throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
  2. String parameterizedHost = Joiner.on(", ").join("{accountName}", accountName, "{adlaCatalogDnsSuffix}", this.client.adlaCatalogDnsSuffix());
  3. return service.deleteSecret(databaseName, secretName, this.client.apiVersion(), this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
  4. .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Void>>>() {
  5. @Override
  6. public Observable<ServiceResponse<Void>> call(Response<ResponseBody> response) {

代码示例来源:origin: Azure/azure-libraries-for-java

  1. throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
  2. String parameterizedHost = Joiner.on(", ").join("{accountName}", accountName, "{adlaCatalogDnsSuffix}", this.client.adlaCatalogDnsSuffix());
  3. return service.getCredential(databaseName, credentialName, this.client.apiVersion(), this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
  4. .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<USqlCredential>>>() {
  5. @Override
  6. public Observable<ServiceResponse<USqlCredential>> call(Response<ResponseBody> response) {

代码示例来源:origin: Azure/azure-libraries-for-java

  1. throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
  2. Validator.validate(parameters);
  3. String parameterizedHost = Joiner.on(", ").join("{accountName}", accountName, "{adlaJobDnsSuffix}", this.client.adlaJobDnsSuffix());
  4. return service.beginUpdate(jobIdentity, parameters, this.client.apiVersion(), this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
  5. .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<JobInformation>>>() {
  6. @Override
  7. public Observable<ServiceResponse<JobInformation>> call(Response<ResponseBody> response) {

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

  1. protected RollingConcurrencyStream(final HystrixEventStream<HystrixCommandExecutionStarted> inputEventStream, final int numBuckets, final int bucketSizeInMs) {
  2. final List<Integer> emptyRollingMaxBuckets = new ArrayList<Integer>();
  3. for (int i = 0; i < numBuckets; i++) {
  4. emptyRollingMaxBuckets.add(0);
  5. }
  6. rollingMaxStream = inputEventStream
  7. .observe()
  8. .map(getConcurrencyCountFromEvent)
  9. .window(bucketSizeInMs, TimeUnit.MILLISECONDS)
  10. .flatMap(reduceStreamToMax)
  11. .startWith(emptyRollingMaxBuckets)
  12. .window(numBuckets, 1)
  13. .flatMap(reduceStreamToMax)
  14. .share()
  15. .onBackpressureDrop();
  16. }

代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources

  1. throw new IllegalArgumentException("Parameter parameters is required and cannot be null.");
  2. Validator.validate(parameters);
  3. return service.beginCreateOrUpdateById(resourceId, apiVersion, parameters, this.client.acceptLanguage(), this.client.userAgent())
  4. .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<GenericResourceInner>>>() {
  5. @Override
  6. public Observable<ServiceResponse<GenericResourceInner>> call(Response<ResponseBody> response) {

代码示例来源:origin: Azure/azure-libraries-for-java

  1. throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
  2. String parameterizedHost = Joiner.on(", ").join("{accountName}", accountName, "{adlaCatalogDnsSuffix}", this.client.adlaCatalogDnsSuffix());
  3. return service.getAssembly(databaseName, assemblyName, this.client.apiVersion(), this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
  4. .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<USqlAssembly>>>() {
  5. @Override
  6. public Observable<ServiceResponse<USqlAssembly>> call(Response<ResponseBody> response) {

代码示例来源:origin: Azure/azure-libraries-for-java

  1. throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
  2. Validator.validate(parameters);
  3. final String op = "REVOKEACE";
  4. String parameterizedHost = Joiner.on(", ").join("{accountName}", accountName, "{adlaCatalogDnsSuffix}", this.client.adlaCatalogDnsSuffix());
  5. return service.revokeAclFromDatabase(databaseName, parameters, op, this.client.apiVersion(), this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
  6. .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Void>>>() {
  7. @Override
  8. public Observable<ServiceResponse<Void>> call(Response<ResponseBody> response) {

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

  1. public Observable<CollectionIoEvent<MvccEntity>> stageRunner( CollectionIoEvent<Entity> writeData,
  2. WriteStart writeState ) {
  3. return Observable.just( writeData ).map( writeState ).flatMap( mvccEntityCollectionIoEvent -> {
  4. Observable<CollectionIoEvent<MvccEntity>> uniqueObservable =
  5. Observable.just( mvccEntityCollectionIoEvent ).subscribeOn( rxTaskScheduler.getAsyncIOScheduler() )
  6. .doOnNext( writeVerifyUnique );
  7. // optimistic verification
  8. Observable<CollectionIoEvent<MvccEntity>> optimisticObservable =
  9. Observable.just( mvccEntityCollectionIoEvent ).subscribeOn( rxTaskScheduler.getAsyncIOScheduler() )
  10. .doOnNext( writeOptimisticVerify );
  11. final Observable<CollectionIoEvent<MvccEntity>> zip =
  12. Observable.zip( uniqueObservable, optimisticObservable, ( unique, optimistic ) -> optimistic );
  13. return zip;
  14. } );
  15. }

代码示例来源:origin: com.microsoft.azure.resources.v2018_02_01/azure-mgmt-resources

  1. throw new IllegalArgumentException("Parameter parameters is required and cannot be null.");
  2. Validator.validate(parameters);
  3. return service.beginUpdateById(resourceId, apiVersion, parameters, this.client.acceptLanguage(), this.client.userAgent())
  4. .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<GenericResourceInner>>>() {
  5. @Override
  6. public Observable<ServiceResponse<GenericResourceInner>> call(Response<ResponseBody> response) {

代码示例来源:origin: Azure/azure-libraries-for-java

  1. throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
  2. String parameterizedHost = Joiner.on(", ").join("{accountName}", accountName, "{adlaCatalogDnsSuffix}", this.client.adlaCatalogDnsSuffix());
  3. return service.getSchema(databaseName, schemaName, this.client.apiVersion(), this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
  4. .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<USqlSchema>>>() {
  5. @Override
  6. public Observable<ServiceResponse<USqlSchema>> call(Response<ResponseBody> response) {

代码示例来源:origin: Azure/azure-libraries-for-java

  1. throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
  2. Validator.validate(parameters);
  3. String parameterizedHost = Joiner.on(", ").join("{accountName}", accountName, "{adlaJobDnsSuffix}", this.client.adlaJobDnsSuffix());
  4. return service.build(parameters, this.client.apiVersion(), this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
  5. .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<JobInformation>>>() {
  6. @Override
  7. public Observable<ServiceResponse<JobInformation>> call(Response<ResponseBody> response) {

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

  1. .getLiveUrl(cid)
  2. .compose(this.bindToLifecycle())
  3. .map(responseBody -> {
  4. try {
  5. String str = responseBody.string();
  6. .flatMap(new Func1<String, Observable<Long>>() {
  7. @Override
  8. public Observable<Long> call(String s) {

代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources

  1. throw new IllegalArgumentException("Parameter parameters is required and cannot be null.");
  2. Validator.validate(parameters);
  3. final String apiVersion = "2016-12-01";
  4. return service.createOrUpdateAtManagementGroup(policyDefinitionName, managementGroupId, parameters, apiVersion, this.client.acceptLanguage(), this.client.userAgent())
  5. .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<PolicyDefinitionInner>>>() {
  6. @Override
  7. public Observable<ServiceResponse<PolicyDefinitionInner>> call(Response<ResponseBody> response) {

代码示例来源:origin: Azure/azure-libraries-for-java

  1. throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
  2. String parameterizedHost = Joiner.on(", ").join("{accountName}", accountName, "{adlaCatalogDnsSuffix}", this.client.adlaCatalogDnsSuffix());
  3. return service.getSecret(databaseName, secretName, this.client.apiVersion(), this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
  4. .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<USqlSecret>>>() {
  5. @Override
  6. public Observable<ServiceResponse<USqlSecret>> call(Response<ResponseBody> response) {

代码示例来源:origin: Azure/azure-libraries-for-java

  1. throw new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null.");
  2. Validator.validate(parameters);
  3. final String op = "GRANTACE";
  4. String parameterizedHost = Joiner.on(", ").join("{accountName}", accountName, "{adlaCatalogDnsSuffix}", this.client.adlaCatalogDnsSuffix());
  5. return service.grantAcl(parameters, op, this.client.apiVersion(), this.client.acceptLanguage(), parameterizedHost, this.client.userAgent())
  6. .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Void>>>() {
  7. @Override
  8. public Observable<ServiceResponse<Void>> call(Response<ResponseBody> response) {

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

  1. @Override
  2. public Observable<MarkedEdge> compactNode( final Id inputNode ) {
  3. final UUID startTime = UUIDGenerator.newTimeUUID();
  4. final Observable<MarkedEdge> nodeObservable =
  5. Observable.just( inputNode )
  6. .map( node -> nodeSerialization.getMaxVersion( scope, node ) )
  7. //.doOnNext(maxTimestamp -> logger.info("compactNode maxTimestamp={}", maxTimestamp.toString()))
  8. .takeWhile(maxTimestamp -> maxTimestamp.isPresent() )
  9. //map our delete listener
  10. .flatMap( timestamp -> nodeDeleteListener.receive( scope, inputNode, startTime ) );
  11. return ObservableTimer.time( nodeObservable, this.deleteNodeTimer );
  12. }

代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources

  1. throw new IllegalArgumentException("Parameter parameters is required and cannot be null.");
  2. Validator.validate(parameters);
  3. return service.beginUpdateById(resourceId, apiVersion, parameters, this.client.acceptLanguage(), this.client.userAgent())
  4. .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<GenericResourceInner>>>() {
  5. @Override
  6. public Observable<ServiceResponse<GenericResourceInner>> call(Response<ResponseBody> response) {

相关文章

Observable类方法