io.vavr.Value Java Examples
The following examples show how to use
io.vavr.Value.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CompletableFutures.java From ts-reaktive with MIT License | 6 votes |
/** * Returns a future that completes when all the futures in the given collection have completed. */ public static <T,U extends T> CompletableFuture<Vector<T>> sequence(Value<? extends CompletionStage<U>> completionStages) { CompletableFuture<Vector<T>> result = new CompletableFuture<>(); Value<CompletableFuture<U>> futures = completionStages.map(f -> f.toCompletableFuture()); // We don't join() the futures until allOf() has completed, since otherwise we'll be blocking // a thread on the common thread pool all the time we're waiting @SuppressWarnings({ "unchecked", "rawtypes" }) CompletableFuture<?>[] array = futures.toJavaArray((Class) CompletableFuture.class); CompletableFuture.allOf(array).whenComplete((done, exception) -> { if (exception != null) { result.completeExceptionally(exception); } else { result.complete(Vector.narrow(futures.map(f -> f.join()).toVector())); } }); return result; }
Example #2
Source File: VavrExceptionHandlingUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void exceptionCausingMethod_UsingTry_ThenSuccess() { integers.stream() .map(CheckedFunction1.liftTry(VavrExceptionHandlingUnitTest::readFromFile)) .flatMap(Value::toJavaStream) .forEach(i -> LOG.debug("{}", i)); }
Example #3
Source File: GraphReadUtils.java From timbuctoo with GNU General Public License v3.0 | 4 votes |
public static String[] getEntityTypesOrDefault(Element element) { return getEntityTypes(element).flatMap(Value::toJavaOptional).orElse(new String[]{}); }