/** * Transforms this tuple to an object of type U. * * @param f Transformation which creates a new object of type U based on this tuple's contents. * @param <U> type of the transformation result * @return An object of type U * @throws NullPointerException if {@code f} is null */ public <U> U apply(BiFunction<? super T1, ? super T2, ? extends U> f) { Objects.requireNonNull(f, "f is null"); return f.apply(_1, _2); }
/** * Creates the available {@link EventLoopGroup}. */ public EventLoopGroup newEventLoopGroup(int nThreads, Function<TransportType, ThreadFactory> threadFactoryFactory) { final ThreadFactory threadFactory = threadFactoryFactory.apply(this); return eventLoopGroupConstructor.apply(nThreads, threadFactory); }
/** * Wait for the result from this mono, use it to create a second mono via the * provided {@code rightGenerator} function and combine both results into an arbitrary * {@code O} object, as defined by the provided {@code combinator} function. * * <p> * <img class="marble" src="doc-files/marbles/zipWhenWithZipperForMono.svg" alt=""> * * @param rightGenerator the {@link Function} to generate a {@code Mono} to combine with * @param combinator a {@link BiFunction} combinator function when both sources complete * @param <T2> the element type of the other Mono instance * @param <O> the element type of the combination * * @return a new combined Mono */ public final <T2, O> Mono<O> zipWhen(Function<T, Mono<? extends T2>> rightGenerator, BiFunction<T, T2, O> combinator) { Objects.requireNonNull(rightGenerator, "rightGenerator function is mandatory to get the right-hand side Mono"); Objects.requireNonNull(combinator, "combinator function is mandatory to combine results from both Monos"); return flatMap(t -> rightGenerator.apply(t).map(t2 -> combinator.apply(t, t2))); }
@Override default <U> U foldLeft(U zero, BiFunction<? super U, ? super T, ? extends U> f) { Objects.requireNonNull(f, "f is null"); U xs = zero; for (T x : this) { xs = f.apply(xs, x); } return xs; }
@Override public CompletableFuture<V1> compute(K1 key, BiFunction<? super K1, ? super V1, ? extends V1> remappingFunction) { return backingMap.compute(keyEncoder.apply(key), (k, v) -> valueEncoder.apply(remappingFunction.apply(keyDecoder.apply(k), valueDecoder.apply(v)))) .thenApply(valueDecoder); }
/** * Return a composed function that first applies this CheckedFunction2 to the given arguments and in case of throwable * try to get value from {@code recover} function with same arguments and throwable information. * * @param recover the function applied in case of throwable * @return a function composed of this and recover * @throws NullPointerException if recover is null */ default Function2<T1, T2, R> recover(Function<? super Throwable, ? extends BiFunction<? super T1, ? super T2, ? extends R>> recover) { Objects.requireNonNull(recover, "recover is null"); return (t1, t2) -> { try { return this.apply(t1, t2); } catch (Throwable throwable) { final BiFunction<? super T1, ? super T2, ? extends R> func = recover.apply(throwable); Objects.requireNonNull(func, () -> "recover return null for " + throwable.getClass() + ": " + throwable.getMessage()); return func.apply(t1, t2); } }; }
/** * Maps the components of this tuple using a mapper function. * * @param mapper the mapper function * @param <U1> new type of the 1st component * @param <U2> new type of the 2nd component * @return A new Tuple of same arity. * @throws NullPointerException if {@code mapper} is null */ public <U1, U2> Tuple2<U1, U2> map(BiFunction<? super T1, ? super T2, Tuple2<U1, U2>> mapper) { Objects.requireNonNull(mapper, "mapper is null"); return mapper.apply(_1, _2); }
/** * A simple function that takes a list of things, asks for their names and checks that the * names are unique within that list. If not it calls the error handler function * * @param errors the error list * @param listOfNamedThings the list of named things * @param namer the function naming a thing * @param errorFunction the function producing an error */ static <T, E extends GraphQLError> void checkNamedUniqueness(List<GraphQLError> errors, List<T> listOfNamedThings, Function<T, String> namer, BiFunction<String, T, E> errorFunction) { Set<String> names = new LinkedHashSet<>(); listOfNamedThings.forEach(thing -> { String name = namer.apply(thing); if (names.contains(name)) { errors.add(errorFunction.apply(name, thing)); } else { names.add(name); } }); }
static <T, U, R extends Traversable<U>> R scanRight(Traversable<? extends T> source, U zero, BiFunction<? super T, ? super U, ? extends U> operation, Function<Iterator<U>, R> finisher) { Objects.requireNonNull(operation, "operation is null"); final Iterator<? extends T> reversedElements = reverseIterator(source); return scanLeft(reversedElements, zero, (u, t) -> operation.apply(t, u), us -> finisher.apply(reverseIterator(us))); }
@Override public <U> U reduce(U identity, BiFunction<U, ? super T, U> accumulator, BinaryOperator<U> combiner) { requireNonNull(accumulator); // the combiner is never used in a non-parallell stream return accumulator.apply(identity, element); }
@Override public CompletableFuture<V1> computeIfPresent(K1 key, BiFunction<? super K1, ? super V1, ? extends V1> remappingFunction) { return backingMap.computeIfPresent(keyEncoder.apply(key), (k, v) -> valueEncoder.apply(remappingFunction.apply(keyDecoder.apply(k), valueDecoder.apply(v)))) .thenApply(valueDecoder); }
@SuppressWarnings("unchecked") static <K, V, K2, U extends Map<K2, V>> U mapKeys(Map<K, V> source, U zero, Function<? super K, ? extends K2> keyMapper, BiFunction<? super V, ? super V, ? extends V> valueMerge) { Objects.requireNonNull(zero, "zero is null"); Objects.requireNonNull(keyMapper, "keyMapper is null"); Objects.requireNonNull(valueMerge, "valueMerge is null"); return source.foldLeft(zero, (acc, entry) -> { final K2 k2 = keyMapper.apply(entry._1); final V v2 = entry._2; final Option<V> v1 = acc.get(k2); final V v = v1.isDefined() ? valueMerge.apply(v1.get(), v2) : v2; return (U) acc.put(k2, v); }); }
default <T1, T2> Tuple2<Seq<T1>, Seq<T2>> unzip(BiFunction<? super K, ? super V, Tuple2<? extends T1, ? extends T2>> unzipper) { Objects.requireNonNull(unzipper, "unzipper is null"); return unzip(entry -> unzipper.apply(entry._1, entry._2)); }
p = Objects.requireNonNull(leftEnd.apply(left), "The leftEnd returned a null Publisher"); w = Objects.requireNonNull(resultSelector.apply(left, up), "The resultSelector returned a null value"); p = Objects.requireNonNull(rightEnd.apply(right), "The rightEnd returned a null Publisher");
default <T1, T2, T3> Tuple3<Seq<T1>, Seq<T2>, Seq<T3>> unzip3(BiFunction<? super K, ? super V, Tuple3<? extends T1, ? extends T2, ? extends T3>> unzipper) { Objects.requireNonNull(unzipper, "unzipper is null"); return unzip3(entry -> unzipper.apply(entry._1, entry._2)); }
@Override public CompletableFuture<Versioned<V1>> computeIf(K1 key, Predicate<? super V1> condition, BiFunction<? super K1, ? super V1, ? extends V1> remappingFunction) { try { return backingMap.computeIf(keyEncoder.apply(key), v -> condition.test(valueDecoder.apply(v)), (k, v) -> valueEncoder.apply(remappingFunction.apply(keyDecoder.apply(k), valueDecoder.apply(v)))) .thenApply(versionedValueDecoder); } catch (Exception e) { return Futures.exceptionalFuture(e); } }
p = Objects.requireNonNull(leftEnd.apply(left), "The leftEnd returned a null Publisher"); w = Objects.requireNonNull(resultSelector.apply(left, right), "The resultSelector returned a null value"); p = Objects.requireNonNull(rightEnd.apply(right), "The rightEnd returned a null Publisher"); w = Objects.requireNonNull(resultSelector.apply(left, right), "The resultSelector returned a null value");
default <T1, T2> Tuple2<Seq<T1>, Seq<T2>> unzip(BiFunction<? super K, ? super V, Tuple2<? extends T1, ? extends T2>> unzipper) { Objects.requireNonNull(unzipper, "unzipper is null"); return unzip(entry -> unzipper.apply(entry._1, entry._2)); }
@Override public Object parseValue(CommandSource source, CommandArgs args) throws ArgumentParseException { final String input = args.next(); try { if (this.parseRadixFunction != null) { if (input.startsWith("0x")) { return this.parseRadixFunction.apply(input.substring(2), 16); } else if (input.startsWith("0b")) { return this.parseRadixFunction.apply(input.substring(2), 2); } } return this.parseFunc.apply(input); } catch (NumberFormatException ex) { throw args.createError(this.errorSupplier.apply(input)); } } }