当前位置: 首页>>代码示例>>Java>>正文


Java BiFunction类代码示例

本文整理汇总了Java中io.reactivex.functions.BiFunction的典型用法代码示例。如果您正苦于以下问题:Java BiFunction类的具体用法?Java BiFunction怎么用?Java BiFunction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BiFunction类属于io.reactivex.functions包,在下文中一共展示了BiFunction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCreate

import io.reactivex.functions.BiFunction; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    recyclerView = (RecyclerView) findViewById(R.id.recyclerview);

    recyclerView.setLayoutManager(new LinearLayoutManager(getBaseContext()));
    adapter = new Adapter();
    recyclerView.setAdapter(adapter);

    loadWithRetroJsoup();

    Observable.zip(
            Observable.just(""),
            Observable.just("&"),
            new BiFunction<String, String, String>(){

                @Override
                public String apply(@NonNull String s, @NonNull String s2) throws Exception {
                    return null;
                }
            }
    );
}
 
开发者ID:florent37,项目名称:RxRetroJsoup,代码行数:25,代码来源:MainActivity.java

示例2: reduceWithMultipleItemsThenReturnFunctionResult

import io.reactivex.functions.BiFunction; //导入依赖的package包/类
@Test
public void reduceWithMultipleItemsThenReturnFunctionResult() {
    boolean result = new Collector<Boolean>(configuration)
            .and(true)
            .and(false)
            .and(true)
            .reduce(new BiFunction<Boolean, Boolean, Boolean>() {

                @Override
                public Boolean apply(@NonNull Boolean itemOne, @NonNull Boolean itemTwo) {
                    return itemOne.equals(itemTwo);
                }
            })
            .call();

    assertFalse(result);
}
 
开发者ID:Ahmed-Adel-Ismail,项目名称:J-Chain,代码行数:18,代码来源:CollectorTest.java

示例3: onStep

import io.reactivex.functions.BiFunction; //导入依赖的package包/类
/**
 * Chains another step to be performed after this step completes. If the previous step results in
 * an error and does not emit a new actionable item, future chained onStep calls will not be
 * called.
 *
 * @param func to return the next step when this current step completes. This function will
 *     receive the result of the previous step and the next actionable item to take an action on.
 * @param <TNewValueType> the value type returned by the next step.
 * @param <TNewActionableItem> the actionable item type returned by the next step.
 * @return a {@link Step} to chain more calls to.
 */
public <TNewValueType, TNewActionableItem extends ActionableItem>
    Step<TNewValueType, TNewActionableItem> onStep(
        final BiFunction<T, A, Step<TNewValueType, TNewActionableItem>> func) {
  return new Step<>(
      asObservable()
          .flatMap(
              new Function<
                  Optional<Data<T, A>>,
                  Observable<Optional<Data<TNewValueType, TNewActionableItem>>>>() {
                @Override
                public Observable<Optional<Data<TNewValueType, TNewActionableItem>>> apply(
                    Optional<Data<T, A>> dataOptional) throws Exception {
                  if (dataOptional.isPresent()) {
                    Data<T, A> data = dataOptional.get();
                    return func.apply(data.value, data.actionableItem).asObservable();
                  } else {
                    return Observable.just(
                        Optional.<Data<TNewValueType, TNewActionableItem>>absent());
                  }
                }
              })
          .singleOrError());
}
 
开发者ID:uber,项目名称:RIBs,代码行数:35,代码来源:Step.java

示例4: scanWith

import io.reactivex.functions.BiFunction; //导入依赖的package包/类
private void scanWith(){
    getObservable()
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .scanWith(new Callable<Integer>() {//提供初始值的函数
                @Override
                public Integer call() throws Exception {
                    return 2;
                }
            }, new BiFunction<Integer, Integer, Integer>() {
                @Override
                public Integer apply(@NonNull Integer integer, @NonNull Integer integer2) throws Exception {
                    return integer + integer2;
                }
            }).subscribe(getObserver());
}
 
开发者ID:changjiashuai,项目名称:RxJava2-Android-Sample,代码行数:17,代码来源:ScanExampleActivity.java

示例5: generateDefault

import io.reactivex.functions.BiFunction; //导入依赖的package包/类
@Override
public Single<Metadata> generateDefault() {
  final int[] zMinMax = getMaxMin(tileFilenames(directory));
  return FilesystemUtil
      .getTiles(new File(directory, String.valueOf(zMinMax[1])).getAbsolutePath(), 2)
      .map(FilesystemUtil::toZxy).reduce(UNDEFINED_ZXY, new BiFunction<int[], int[], int[]>() {
        @Override
        public int[] apply(int[] aa, int[] bb) throws Exception {
          return aa == UNDEFINED_ZXY ? (bb == UNDEFINED_ZXY ? UNDEFINED_ZXY : bb)
              : new int[] {Math.max(aa[0], bb[0]), Math.max(aa[1], bb[1]),
              Math.max(aa[2], bb[2])};
        }
      }).map(zxy -> {
        if (zxy == UNDEFINED_ZXY) {
          return new Metadata.Builder().build();
        }
        // TODO should be able to translate tile coordinates to
        // bounds shortly!
        return new Metadata.Builder().setMinZoom(zMinMax[0]).setMaxZoom(zMinMax[1]).build();
      }).toObservable().singleOrError();
}
 
开发者ID:OrdnanceSurvey,项目名称:vt-support,代码行数:22,代码来源:StorageImpl.java

示例6: reducer

import io.reactivex.functions.BiFunction; //导入依赖的package包/类
@NonNull
private BiFunction<UIModel<S>, Result<?>, UIModel<S>> reducer() {
    return (currentUIModel, result) -> {
        String event = result.getEvent();
        S bundle = currentUIModel.getBundle();
        if (result.isLoading()) {
            currentUIModel = loadingState(create(event, bundle));
        } else if (result.isSuccessful()) {
            currentUIModel = successState(create(event,
                    stateReducer().reduce(result.getBundle(), event, bundle)));
        } else {
            currentUIModel = errorState(result.getThrowable(), create(event, bundle));
        }
        return currentUIModel;
    };
}
 
开发者ID:Zeyad-37,项目名称:RxRedux,代码行数:17,代码来源:BaseViewModel.java

示例7: DifferentialFlowableList

import io.reactivex.functions.BiFunction; //导入依赖的package包/类
DifferentialFlowableList(Flowable<List<T>> list, boolean detectMoves)
{
    _detectMoves = detectMoves;
    _diffTransform = list
            .map(new Function<List<T>, Update<T>>() {
                @Override
                public Update<T> apply(List<T> ts) {
                    return new Update<>(ts, Change.reloaded());
                }
            })
            .scan(new BiFunction<Update<T>, Update<T>, Update<T>>() {
                @Override
                public Update<T> apply(Update<T> previous, Update<T> next) {
                    if (previous == null) {
                        return next;
                    }

                    List<Change> changes = computeDiff(previous.list, next.list);

                    _previousList = next.list;

                    return new Update<>(next.list, changes);
                }
            });
}
 
开发者ID:mproberts,项目名称:rxtools,代码行数:26,代码来源:DifferentialFlowableList.java

示例8: collectStats

import io.reactivex.functions.BiFunction; //导入依赖的package包/类
public static <T, R extends Number> FlowableTransformer<T, Pair<T, Statistics>> collectStats(
        final Function<? super T, ? extends R> function) {
    return new FlowableTransformer<T, Pair<T, Statistics>>() {

        @Override
        public Flowable<Pair<T, Statistics>> apply(Flowable<T> source) {
            return source.scan(Pair.create((T) null, Statistics.create()),
                    new BiFunction<Pair<T, Statistics>, T, Pair<T, Statistics>>() {
                        @Override
                        public Pair<T, Statistics> apply(Pair<T, Statistics> pair, T t) throws Exception {
                            return Pair.create(t, pair.b().add(function.apply(t)));
                        }
                    }).skip(1);
        }
    };
}
 
开发者ID:davidmoten,项目名称:rxjava2-extras,代码行数:17,代码来源:Transformers.java

示例9: apply

import io.reactivex.functions.BiFunction; //导入依赖的package包/类
@Override
public Observable<?> apply(Observable<? extends Throwable> flowable) throws Exception {
    return flowable.zipWith(Observable.range(1, count + 1), new BiFunction<Throwable, Integer, Wrapper>() {
        @Override
        public Wrapper apply(Throwable throwable, Integer integer) throws Exception {
            return new Wrapper(throwable, integer);
        }
    }).flatMap(wrapper -> {
        if ((wrapper.throwable instanceof ConnectException
                || wrapper.throwable instanceof SocketTimeoutException
                || wrapper.throwable instanceof TimeoutException)
                && wrapper.index < count + 1) {
            return Observable.timer(delay + (wrapper.index - 1) * delay, TimeUnit.MILLISECONDS);
        }
        return Observable.error(wrapper.throwable);
    } );
}
 
开发者ID:dalingge,项目名称:GankGirl,代码行数:18,代码来源:RetryWhenNetworkException.java

示例10: testElementsList

import io.reactivex.functions.BiFunction; //导入依赖的package包/类
@Test
public void testElementsList() throws Exception {
    List<TestObject> elements = new ArrayList<>();
    elements.add(new TestObject(1, 9.5, "a"));
    elements.add(new TestObject(2, 6.7, "ab"));
    elements.add(new TestObject(3, 8.2, "abc"));
    elements.add(new TestObject(4, 3.4, "abcd"));
    elements.add(new TestObject(5, 6.5, "abcde"));
    SQLite.get().insert(TestTable.TABLE, elements);

    Observable.zip(RxSQLite.get().query(TestTable.TABLE),
            Observable.just(elements), new BiFunction<List<TestObject>, List<TestObject>, Object>() {
                @Override
                public Object apply(List<TestObject> testElements, List<TestObject> savedElements) throws Exception {
                    assertEquals(testElements.size(), savedElements.size());
                    for (int i = 0; i < testElements.size(); i++) {
                        assertEquals(testElements.size(), savedElements.size());
                    }
                    return null;
                }
            })
            .test();
}
 
开发者ID:ArturVasilov,项目名称:SQLite,代码行数:24,代码来源:RxSQLiteTest.java

示例11: practice1

import io.reactivex.functions.BiFunction; //导入依赖的package包/类
public static void practice1(){
    final Api api = RetrofitProvider.get().create(Api.class);
    Observable<UserBaseInfoResponse> observable1 =
            api.getUserBaseInfo(new UserBaseInfoRequest()).subscribeOn(Schedulers.io());

    Observable<UserExtraInfoResponse> observable2 =
            api.getUserExtraInfo(new UserExtraInfoRequest()).subscribeOn(Schedulers.io());

    Observable.zip(observable1, observable2,
            new BiFunction<UserBaseInfoResponse, UserExtraInfoResponse, UserInfo>() {
                @Override
                public UserInfo apply(UserBaseInfoResponse baseInfo,
                                      UserExtraInfoResponse extraInfo) throws Exception {
                    return new UserInfo(baseInfo, extraInfo);
                }
            }).observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Consumer<UserInfo>() {
                @Override
                public void accept(UserInfo userInfo) throws Exception {
                    //do something;
                }
            });
}
 
开发者ID:ssseasonnn,项目名称:RxJava2Demo,代码行数:24,代码来源:ChapterFour.java

示例12: avgFunction

import io.reactivex.functions.BiFunction; //导入依赖的package包/类
@Test
public void avgFunction() {
  final double count = 8;
  final Integer sum = Observable.fromIterable(insertSimpleAllValues((int) count))
      .map(new Function<SimpleAllValuesMutable, Integer>() {
        @Override
        public Integer apply(SimpleAllValuesMutable v) {
          return (int) v.primitiveShort;
        }
      })
      .reduce(new BiFunction<Integer, Integer, Integer>() {
        @Override
        public Integer apply(Integer v1, Integer v2) {
          return v1 + v2;
        }
      })
      .blockingGet();

  final Double value = Select
      .column(avg(SIMPLE_ALL_VALUES_MUTABLE.PRIMITIVE_SHORT))
      .from(SIMPLE_ALL_VALUES_MUTABLE)
      .takeFirst()
      .execute();
  assertThat(value).isEqualTo(sum.doubleValue() / count);
}
 
开发者ID:SiimKinks,项目名称:sqlitemagic,代码行数:26,代码来源:SynchronousColumnQueryTest.java

示例13: loadStringArray

import io.reactivex.functions.BiFunction; //导入依赖的package包/类
private void loadStringArray(final StudyContentDao studyContentDao) {
    String[] titleList = getResources().getStringArray(R.array.study_ui_title);
    String[] descList = getResources().getStringArray(R.array.study_ui_description);
    Observable<String> observableTitle = Observable.fromArray(titleList);
    Observable<String> observableDescList = Observable.fromArray(descList);

    Observable.zip(observableTitle, observableDescList, new BiFunction<String, String, StudyContent>() {
        @Override
        public StudyContent apply(@io.reactivex.annotations.NonNull String s, @io.reactivex.annotations.NonNull String s2) throws Exception {
            StudyContent studyItemModel = new StudyContent();
            studyItemModel.setTitle(s);
            studyItemModel.setDescription(s2);
            studyItemModel.setType(s);
            return studyItemModel;
        }
    }).subscribe(new Consumer<StudyContent>() {
        @Override
        public void accept(@io.reactivex.annotations.NonNull StudyContent studyContent) throws Exception {
            studyContentDao.insertOrReplace(studyContent);
        }
    });
}
 
开发者ID:yzbzz,项目名称:beautifullife,代码行数:23,代码来源:App.java

示例14: findUsersWhoLovesBoth

import io.reactivex.functions.BiFunction; //导入依赖的package包/类
private void findUsersWhoLovesBoth() {
    // here we are using zip operator to combine both request
    Observable.zip(getCricketFansObservable(), getFootballFansObservable(),
            new BiFunction<List<User>, List<User>, List<User>>() {
                @Override
                public List<User> apply(List<User> cricketFans, List<User> footballFans) throws Exception {
                    List<User> userWhoLovesBoth =
                            filterUserWhoLovesBoth(cricketFans, footballFans);
                    return userWhoLovesBoth;
                }
            })
            .subscribeOn(Schedulers.newThread())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Observer<List<User>>() {
                @Override
                public void onSubscribe(Disposable d) {

                }

                @Override
                public void onNext(List<User> users) {
                    // do anything with user who loves both
                    Log.d(TAG, "userList size : " + users.size());
                    for (User user : users) {
                        Log.d(TAG, "user : " + user.toString());
                    }
                }

                @Override
                public void onError(Throwable e) {
                    Utils.logError(TAG, e);
                }

                @Override
                public void onComplete() {
                    Log.d(TAG, "onComplete");
                }
            });
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:40,代码来源:NetworkingActivity.java

示例15: doSomeWork

import io.reactivex.functions.BiFunction; //导入依赖的package包/类
private void doSomeWork() {
    getObservable()
            // Run on a background thread
            .subscribeOn(Schedulers.io())
            // Be notified on the main thread
            .observeOn(AndroidSchedulers.mainThread())
            .scan(new BiFunction<Integer, Integer, Integer>() {
                @Override
                public Integer apply(Integer int1, Integer int2) throws Exception {
                    return int1 + int2;
                }
            })
            .subscribe(getObserver());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:ScanExampleActivity.java


注:本文中的io.reactivex.functions.BiFunction类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。