本文整理了Java中io.reactivex.Single.zipWith()
方法的一些代码示例,展示了Single.zipWith()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Single.zipWith()
方法的具体详情如下:
包路径:io.reactivex.Single
类名称:Single
方法名:zipWith
[英]Returns a Single that emits the result of applying a specified function to the pair of items emitted by the source Single and another specified Single.
Scheduler: zipWith does not operate by default on a particular Scheduler.
[中]返回一个Single,该Single将指定函数应用于源Single和另一个指定Single发出的项对的结果。
调度器:zipWith默认情况下不会在特定的调度器上运行。
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void zipWithNull() {
just1.zipWith(null, new BiFunction<Integer, Object, Object>() {
@Override
public Object apply(Integer a, Object b) {
return 1;
}
});
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void zipWithFunctionNull() {
just1.zipWith(just1, null);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(expected = NullPointerException.class)
public void zipWithFunctionReturnsNull() {
just1.zipWith(just1, new BiFunction<Integer, Integer, Object>() {
@Override
public Object apply(Integer a, Integer b) {
return null;
}
}).blockingGet();
}
}
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
// Create two requests
WebClient client = WebClient.create(vertx);
Single<JsonObject> request = client.get(8080, "localhost", "/")
.as(BodyCodec.jsonObject())
.rxSend()
.map(resp -> resp.body());
// Combine the responses with the zip into a single response
request
.zipWith(request, (b1, b2) -> new JsonObject().put("req1", b1).put("req2", b2))
.subscribe(json -> {
System.out.println("Got combined result " + json);
}, err -> {
err.printStackTrace();
});
}
}
代码示例来源:origin: vert-x3/vertx-examples
Single<int[]> reply = reply1.zipWith(reply2, (msg1, msg2) -> new int[]{msg1.body(), msg2.body()});
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testZipWith() {
TestSubscriber<String> ts = new TestSubscriber<String>();
Single.just("A").zipWith(Single.just("B"), new BiFunction<String, String, String>() {
@Override
public String apply(String a1, String b1) {
return a1 + b1;
}
})
.toFlowable().subscribe(ts);
ts.assertValueSequence(Arrays.asList("AB"));
}
代码示例来源:origin: pockethub/PocketHub
public Single<FullTree> refresh() {
GitService gitService = ServiceGenerator.createService(context, GitService.class);
return getBranch(reference)
.map(branch -> branch.replace("heads/", ""))
.flatMap(branch -> getValidRef(gitService, reference, branch))
.flatMap(reference ->
gitService.getGitCommit(repo.owner().login(), repo.name(),
reference.object().sha())
.map(Response::body)
.zipWith(Single.just(reference), RefreshTreeModel::new))
.flatMap(model ->
gitService.getGitTreeRecursive(repo.owner().login(),
repo.name(), model.getCommit().tree().sha())
.map(Response::body)
.zipWith(Single.just(model.ref), FullTree::new));
}
代码示例来源:origin: pockethub/PocketHub
})
.flatMap(issue -> getAllComments(repo.owner().login(), repo.name(), issue)
.zipWith(Single.just(issue),
(comments, issue1) -> new FullIssue(issue1, comments, Collections.emptyList())))
.zipWith(getAllEvents(repo.owner().login(), repo.name(), issueNumber),
(fullIssue, issueEvents) -> new FullIssue(fullIssue.getIssue(),
fullIssue.getComments(), issueEvents))
代码示例来源:origin: FroMage/redpipe
@Path("composed")
@GET
public Single<String> helloComposed(@Context Vertx vertx) {
Single<String> request1 = get(vertx, getURI(HelloResource::hello));
Single<String> request2 = get(vertx, getURI(HelloResource::helloReactive));
return request1.zipWith(request2, (hello1, hello2) -> hello1 + "\n" + hello2);
}
代码示例来源:origin: io.gravitee.am.gateway.handlers/gravitee-am-gateway-handler
private void getOAuth2Identities(Set<String> oauth2Identities, HttpServerRequest request, Handler<AsyncResult<List<OAuth2ProviderData>>> resultHandler) {
Observable.fromIterable(oauth2Identities)
.flatMapSingle(oauth2Identity -> getIdentityProvider(oauth2Identity)
.zipWith(getAuthorizeUrl(oauth2Identity, request),
(identityProvider, authorizeUrl) -> new OAuth2ProviderData(identityProvider, authorizeUrl)))
.toList()
.subscribe(identityProviders -> resultHandler.handle(Future.succeededFuture(identityProviders)),
error -> resultHandler.handle(Future.failedFuture(error)));
}
代码示例来源:origin: gravitee-io/graviteeio-access-management
private void getOAuth2Identities(Set<String> oauth2Identities, HttpServerRequest request, Handler<AsyncResult<List<OAuth2ProviderData>>> resultHandler) {
Observable.fromIterable(oauth2Identities)
.flatMapSingle(oauth2Identity -> getIdentityProvider(oauth2Identity)
.zipWith(getAuthorizeUrl(oauth2Identity, request),
(identityProvider, authorizeUrl) -> new OAuth2ProviderData(identityProvider, authorizeUrl)))
.toList()
.subscribe(identityProviders -> resultHandler.handle(Future.succeededFuture(identityProviders)),
error -> resultHandler.handle(Future.failedFuture(error)));
}
代码示例来源:origin: net.redpipe/redpipe-engine
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
Single<Boolean> ret = null;
for (Map.Entry<AuthorizingAnnotationHandler, Annotation> authzCheck : authzChecks.entrySet()) {
AuthorizingAnnotationHandler handler = authzCheck.getKey();
Annotation authzSpec = authzCheck.getValue();
Single<Boolean> check = handler.assertAuthorized(authzSpec);
if(ret == null)
ret = check;
else
ret = ret.zipWith(check, (a, b) -> a && b);
}
if(ret != null) {
PreMatchContainerRequestContext context = (PreMatchContainerRequestContext)requestContext;
context.suspend();
ret.subscribe(result -> {
if (result)
context.resume();
else
context.resume(new AuthorizationException("Authorization failed"));
}, error -> {
context.resume(error);
});
}
}
代码示例来源:origin: FroMage/redpipe
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
Single<Boolean> ret = null;
for (Map.Entry<AuthorizingAnnotationHandler, Annotation> authzCheck : authzChecks.entrySet()) {
AuthorizingAnnotationHandler handler = authzCheck.getKey();
Annotation authzSpec = authzCheck.getValue();
Single<Boolean> check = handler.assertAuthorized(authzSpec);
if(ret == null)
ret = check;
else
ret = ret.zipWith(check, (a, b) -> a && b);
}
if(ret != null) {
PreMatchContainerRequestContext context = (PreMatchContainerRequestContext)requestContext;
context.suspend();
ret.subscribe(result -> {
if (result)
context.resume();
else
context.resume(new AuthorizationException("Authorization failed"));
}, error -> {
context.resume(error);
});
}
}
代码示例来源:origin: ImangazalievM/ReActiveAndroid
private void loadNote() {
Single<Note> noteSingle = Select.from(Note.class)
.where("id = ?", noteId)
.fetchSingleAsync();
Select.from(NoteFolderRelation.class)
.where("note = ?", noteId)
.fetchAsync()
.flatMapObservable(Observable::fromIterable)
.map(NoteFolderRelation::getFolder)
.toList()
.zipWith(noteSingle, (folders, note) -> {
note.setFolders(folders);
return note;
})
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::onNotesLoaded);
}
代码示例来源:origin: FroMage/redpipe
@Override
public Single<Boolean> assertAuthorized(Annotation authzSpec) {
if(authzSpec instanceof RequiresPermissions){
User user = getUser();
if(user == null)
return Single.error(new AuthorizationException("User required"));
Single<Boolean> ret = Single.just(true);
for(String perm : ((RequiresPermissions) authzSpec).value()){
ret = user.rxIsAuthorised(perm).zipWith(ret, (a, b) -> a && b);
}
return ret;
}
return Single.just(true);
}
}
代码示例来源:origin: io.gravitee.am.gateway.handlers/gravitee-am-gateway-handler
.zipWith(scopeService.getAll(), (client, domainScopes) -> {
代码示例来源:origin: gravitee-io/graviteeio-access-management
.zipWith(scopeService.getAll(), (client, domainScopes) -> {
代码示例来源:origin: net.redpipe/redpipe-engine
@Override
public Single<Boolean> assertAuthorized(Annotation authzSpec) {
if(authzSpec instanceof RequiresPermissions){
User user = getUser();
if(user == null)
return Single.error(new AuthorizationException("User required"));
Single<Boolean> ret = Single.just(true);
for(String perm : ((RequiresPermissions) authzSpec).value()){
ret = user.rxIsAuthorised(perm).zipWith(ret, (a, b) -> a && b);
}
return ret;
}
return Single.just(true);
}
}
内容来源于网络,如有侵权,请联系作者删除!