Create a gist now

Instantly share code, notes, and snippets.

public static class FutureCompositions<V , A extends WannabeApplicative<V>>{
private final Supplier<CompletableFuture<Outcome<A>>> _partial;
private FutureCompositions(Supplier<CompletableFuture<Outcome<A>>> state)
{
_partial=state;
}
public FutureCompositions<V, A> binding(Partial<A> stage)
{
return new FutureCompositions<>(() -> stage.apply(_partial.get()));
}
public CompletableFuture<Outcome<V>> perform()
{
return _partial.get().thenApply(p -> p.mapR(WannabeApplicative::apply));
}
public static <V, A extends WannabeApplicative<V>> FutureCompositions<V, A> begin(A applicative)
{
return new FutureCompositions<>(() -> completedFuture(maybe(applicative)));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment