List of usage examples for java.util.function BiFunction apply
R apply(T t, U u);
From source file:Main.java
public static void main(String[] args) { BiFunction<String, String, String> biFunction = (s1, s2) -> s1 + s2; String result = biFunction.apply("Just", "Java 8"); System.out.println("Result: " + result); }
From source file:Main.java
public static void main(String[] argv) { // Uses a lambda expression BiFunction<Integer, Integer, Integer> func1 = (x, y) -> Integer.sum(x, y); System.out.println(func1.apply(2, 3)); // Uses a method reference BiFunction<Integer, Integer, Integer> func2 = Integer::sum; System.out.println(func2.apply(2, 3)); }
From source file:Main.java
public static void main(String[] args) { BiFunction<String, String, String> bi = (x, y) -> { return x + y; };/*from ww w .j a v a 2 s .c o m*/ System.out.println(bi.apply("java2s.com", " tutorial")); }
From source file:Main.java
public static void main(String[] argv) { // Uses Integer.valueOf(int) Function<Integer, Integer> func1 = Integer::valueOf; // Uses Integer.valueOf(String) Function<String, Integer> func2 = Integer::valueOf; // Uses Integer.valueOf(String, int) BiFunction<String, Integer, Integer> func3 = Integer::valueOf; System.out.println(func1.apply(7)); System.out.println(func2.apply("7")); System.out.println(func3.apply("101010101010", 2)); }
From source file:Main.java
public static Map<String, Double> bimapIt(List<Employee> candidates, Double raise, BiFunction<Employee, Double, Double> mapper) { Map<String, Double> applied = new HashMap<>(); for (Employee candidate : candidates) { applied.put(candidate.name, mapper.apply(candidate, raise)); }/*w w w. j a va2s . co m*/ return applied; }
From source file:Main.java
/** * Returns a stream consisting of the results of applying the given two-arguments function to the elements of this stream. * The first argument of the function is the element index and the second one - the element value. *//*from ww w . j av a 2 s.co m*/ public static <T, R> Stream<R> mapWithIndex(Stream<? extends T> stream, BiFunction<Integer, ? super T, ? extends R> mapper, int startIndex) { return zipWithIndex(stream, startIndex).map(entry -> mapper.apply(entry.getKey(), entry.getValue())); }
From source file:Main.java
public static <A, B, C> Stream<C> zip(Stream<A> as, Stream<B> bs, BiFunction<A, B, C> f) { Iterator<A> asIterator = as.iterator(); Iterator<B> bsIterator = bs.iterator(); Builder<C> builder = Stream.builder(); while (asIterator.hasNext() && bsIterator.hasNext()) { builder.add(f.apply(asIterator.next(), bsIterator.next())); }//from w w w .j a v a 2 s .co m return builder.build(); }
From source file:enumj.Reversible.java
/** * Applies a {@code Enumerator.map(BiFunction)} operation * upon {@code source}, in reverse if necessary. * * @param <E> type of unmapped enumerated elements. * @param <R> type of mapped enumerated elements. * @param source {@link Enumerator} to apply the operation on. * @param mapper {@link BiFunction} to apply. * @param reversed true if the operation is applied in reverse, * false otherwise./*from w w w . j a v a 2s.c om*/ * @return mapped {@code Enumerator}. */ static <E, R> Enumerator<R> map(Enumerator<E> source, BiFunction<? super E, ? super Long, ? extends R> mapper, boolean reversed) { Checks.ensureNotNull(mapper, Messages.NULL_ENUMERATOR_MAPPER); final MutableLong index = new MutableLong(0); final Function<E, R> fun = e -> { final R result = mapper.apply(e, index.toLong()); index.increment(); return result; }; if (reversed) { final PipeEnumerator pipe = (PipeEnumerator) source; return pipe.reversedMap(fun); } return source.map(fun); }
From source file:com.github.horrorho.inflatabledonkey.cloud.clients.KeyBagClient.java
static Optional<byte[]> field(CloudKit.Record record, String label, BiFunction<byte[], String, Optional<byte[]>> decrypt) { return record.getRecordFieldList().stream().filter(value -> value.getIdentifier().getName().equals(label)) .map(CloudKit.RecordField::getValue).map(CloudKit.RecordFieldValue::getBytesValue) .map(ByteString::toByteArray).map(bs -> decrypt.apply(bs, label)).filter(Optional::isPresent) .map(Optional::get).findFirst(); }
From source file:at.gridtec.lambda4j.function.bi.BiFunction2.java
/** * Calls the given {@link BiFunction} with the given arguments and returns its result. * * @param <T> The type of the first argument to the function * @param <U> The type of the second argument to the function * @param <R> The type of return value from the function * @param function The function to be called * @param t The first argument to the function * @param u The second argument to the function * @return The result from the given {@code BiFunction2}. * @throws NullPointerException If given argument is {@code null} *///from w w w . j a v a2 s .co m static <T, U, R> R call(@Nonnull final BiFunction<? super T, ? super U, ? extends R> function, T t, U u) { Objects.requireNonNull(function); return function.apply(t, u); }