/** * Yields a result for elements of the cross product of the underlying Options. * * @param f a function that maps an element of the cross product to a result * @param <R> type of the resulting {@code Option} elements * @return an {@code Option} of mapped results */ public <R> Option<R> yield(Function8<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? extends R> f) { Objects.requireNonNull(f, "f is null"); return ts1.flatMap(t1 -> ts2.flatMap(t2 -> ts3.flatMap(t3 -> ts4.flatMap(t4 -> ts5.flatMap(t5 -> ts6.flatMap(t6 -> ts7.flatMap(t7 -> ts8.map(t8 -> f.apply(t1, t2, t3, t4, t5, t6, t7, t8))))))))); }
/** * Yields a result for elements of the cross product of the underlying Options. * * @param f a function that maps an element of the cross product to a result * @param <R> type of the resulting {@code Option} elements * @return an {@code Option} of mapped results */ public <R> Option<R> yield(Function7<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? extends R> f) { Objects.requireNonNull(f, "f is null"); return ts1.flatMap(t1 -> ts2.flatMap(t2 -> ts3.flatMap(t3 -> ts4.flatMap(t4 -> ts5.flatMap(t5 -> ts6.flatMap(t6 -> ts7.map(t7 -> f.apply(t1, t2, t3, t4, t5, t6, t7)))))))); }
/** * Yields a result for elements of the cross product of the underlying Options. * * @param f a function that maps an element of the cross product to a result * @param <R> type of the resulting {@code Option} elements * @return an {@code Option} of mapped results */ public <R> Option<R> yield(Function6<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? extends R> f) { Objects.requireNonNull(f, "f is null"); return ts1.flatMap(t1 -> ts2.flatMap(t2 -> ts3.flatMap(t3 -> ts4.flatMap(t4 -> ts5.flatMap(t5 -> ts6.map(t6 -> f.apply(t1, t2, t3, t4, t5, t6))))))); }
/** * Yields a result for elements of the cross product of the underlying Options. * * @param f a function that maps an element of the cross product to a result * @param <R> type of the resulting {@code Option} elements * @return an {@code Option} of mapped results */ public <R> Option<R> yield(Function5<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? extends R> f) { Objects.requireNonNull(f, "f is null"); return ts1.flatMap(t1 -> ts2.flatMap(t2 -> ts3.flatMap(t3 -> ts4.flatMap(t4 -> ts5.map(t5 -> f.apply(t1, t2, t3, t4, t5)))))); }
/** * Yields a result for elements of the cross product of the underlying Options. * * @param f a function that maps an element of the cross product to a result * @param <R> type of the resulting {@code Option} elements * @return an {@code Option} of mapped results */ public <R> Option<R> yield(Function4<? super T1, ? super T2, ? super T3, ? super T4, ? extends R> f) { Objects.requireNonNull(f, "f is null"); return ts1.flatMap(t1 -> ts2.flatMap(t2 -> ts3.flatMap(t3 -> ts4.map(t4 -> f.apply(t1, t2, t3, t4))))); }
/** * Yields a result for elements of the cross product of the underlying Options. * * @param f a function that maps an element of the cross product to a result * @param <R> type of the resulting {@code Option} elements * @return an {@code Option} of mapped results */ public <R> Option<R> yield(BiFunction<? super T1, ? super T2, ? extends R> f) { Objects.requireNonNull(f, "f is null"); return ts1.flatMap(t1 -> ts2.map(t2 -> f.apply(t1, t2))); }
/** * Yields a result for elements of the cross product of the underlying Options. * * @param f a function that maps an element of the cross product to a result * @param <R> type of the resulting {@code Option} elements * @return an {@code Option} of mapped results */ public <R> Option<R> yield(Function3<? super T1, ? super T2, ? super T3, ? extends R> f) { Objects.requireNonNull(f, "f is null"); return ts1.flatMap(t1 -> ts2.flatMap(t2 -> ts3.map(t3 -> f.apply(t1, t2, t3)))); }
private Option<Collector<?, ?, ?>> resolveDefaultCollector(Class<?> erasedType) { return defaultImplementations.get(erasedType).flatMap(collectors::get); }
/** * Collects value that is in the domain of the given {@code partialFunction} by mapping the value to type {@code R}. * * <pre>{@code * partialFunction.isDefinedAt(value) * }</pre> * * If the element makes it through that filter, the mapped instance is wrapped in {@code Option} * * <pre>{@code * R newValue = partialFunction.apply(value) * }</pre> * * * @param partialFunction A function that is not necessarily defined on value of this option. * @param <R> The new value type * @return A new {@code Option} instance containing value of type {@code R} * @throws NullPointerException if {@code partialFunction} is null */ default <R> Option<R> collect(PartialFunction<? super T, ? extends R> partialFunction) { Objects.requireNonNull(partialFunction, "partialFunction is null"); return flatMap(partialFunction.lift()::apply); }
/** * Yields a result for elements of the cross product of the underlying Options. * * @param f a function that maps an element of the cross product to a result * @param <R> type of the resulting {@code Option} elements * @return an {@code Option} of mapped results */ public <R> Option<R> yield(Function8<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? super T8, ? extends R> f) { Objects.requireNonNull(f, "f is null"); return ts1.flatMap(t1 -> ts2.flatMap(t2 -> ts3.flatMap(t3 -> ts4.flatMap(t4 -> ts5.flatMap(t5 -> ts6.flatMap(t6 -> ts7.flatMap(t7 -> ts8.map(t8 -> f.apply(t1, t2, t3, t4, t5, t6, t7, t8))))))))); }
/** * Yields a result for elements of the cross product of the underlying Options. * * @param f a function that maps an element of the cross product to a result * @param <R> type of the resulting {@code Option} elements * @return an {@code Option} of mapped results */ public <R> Option<R> yield(Function7<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? super T7, ? extends R> f) { Objects.requireNonNull(f, "f is null"); return ts1.flatMap(t1 -> ts2.flatMap(t2 -> ts3.flatMap(t3 -> ts4.flatMap(t4 -> ts5.flatMap(t5 -> ts6.flatMap(t6 -> ts7.map(t7 -> f.apply(t1, t2, t3, t4, t5, t6, t7)))))))); }
/** * Yields a result for elements of the cross product of the underlying Options. * * @param f a function that maps an element of the cross product to a result * @param <R> type of the resulting {@code Option} elements * @return an {@code Option} of mapped results */ public <R> Option<R> yield(Function5<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? extends R> f) { Objects.requireNonNull(f, "f is null"); return ts1.flatMap(t1 -> ts2.flatMap(t2 -> ts3.flatMap(t3 -> ts4.flatMap(t4 -> ts5.map(t5 -> f.apply(t1, t2, t3, t4, t5)))))); }
/** * Yields a result for elements of the cross product of the underlying Options. * * @param f a function that maps an element of the cross product to a result * @param <R> type of the resulting {@code Option} elements * @return an {@code Option} of mapped results */ public <R> Option<R> yield(Function6<? super T1, ? super T2, ? super T3, ? super T4, ? super T5, ? super T6, ? extends R> f) { Objects.requireNonNull(f, "f is null"); return ts1.flatMap(t1 -> ts2.flatMap(t2 -> ts3.flatMap(t3 -> ts4.flatMap(t4 -> ts5.flatMap(t5 -> ts6.map(t6 -> f.apply(t1, t2, t3, t4, t5, t6))))))); }
/** * Yields a result for elements of the cross product of the underlying Options. * * @param f a function that maps an element of the cross product to a result * @param <R> type of the resulting {@code Option} elements * @return an {@code Option} of mapped results */ public <R> Option<R> yield(Function4<? super T1, ? super T2, ? super T3, ? super T4, ? extends R> f) { Objects.requireNonNull(f, "f is null"); return ts1.flatMap(t1 -> ts2.flatMap(t2 -> ts3.flatMap(t3 -> ts4.map(t4 -> f.apply(t1, t2, t3, t4))))); }
/** * Yields a result for elements of the cross product of the underlying Options. * * @param f a function that maps an element of the cross product to a result * @param <R> type of the resulting {@code Option} elements * @return an {@code Option} of mapped results */ public <R> Option<R> yield(BiFunction<? super T1, ? super T2, ? extends R> f) { Objects.requireNonNull(f, "f is null"); return ts1.flatMap(t1 -> ts2.map(t2 -> f.apply(t1, t2))); }
/** * Yields a result for elements of the cross product of the underlying Options. * * @param f a function that maps an element of the cross product to a result * @param <R> type of the resulting {@code Option} elements * @return an {@code Option} of mapped results */ public <R> Option<R> yield(Function3<? super T1, ? super T2, ? super T3, ? extends R> f) { Objects.requireNonNull(f, "f is null"); return ts1.flatMap(t1 -> ts2.flatMap(t2 -> ts3.map(t3 -> f.apply(t1, t2, t3)))); }
/** * Collects value that is in the domain of the given {@code partialFunction} by mapping the value to type {@code R}. * * <pre>{@code * partialFunction.isDefinedAt(value) * }</pre> * * If the element makes it through that filter, the mapped instance is wrapped in {@code Option} * * <pre>{@code * R newValue = partialFunction.apply(value) * }</pre> * * * @param partialFunction A function that is not necessarily defined on value of this option. * @param <R> The new value type * @return A new {@code Option} instance containing value of type {@code R} * @throws NullPointerException if {@code partialFunction} is null */ default <R> Option<R> collect(PartialFunction<? super T, ? extends R> partialFunction) { Objects.requireNonNull(partialFunction, "partialFunction is null"); return flatMap(partialFunction.lift()::apply); }
private Option<EventStore> createEventStore(EventStoreName eventStoreName) { return eventStoreProperties .get(eventStoreName) .map(factory::createEventStore) .peek(store -> store.peekLeft(error -> log.error("could not create event store client with name {}", eventStoreName))) .flatMap(Either::toOption); } }
/** * Call {@link Option#flatMap(Function) flatMap} on the {@code Option} under test, assertions chained afterwards are performed on the {@code Option} resulting from the flatMap call. * * @param <U> the type of a value contained in {@link Option}. * @param mapper the {@link Function} to use in the {@link Option#flatMap(Function) flatMap} operation. * @return a new {@link org.assertj.vavr.api.AbstractOptionAssert} for assertions chaining on the flatMap of the Option. * @throws AssertionError if the actual {@link Option} is null. */ @CheckReturnValue public <U> AbstractOptionAssert<?, U> flatMap(Function<? super VALUE, Option<U>> mapper) { isNotNull(); return VavrAssertions.assertThat(actual.flatMap(mapper)); }