Skip to content

Instantly share code, notes, and snippets.

@gszeliga
Created December 9, 2015 22:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gszeliga/6a5fcd0849a70f901dc5 to your computer and use it in GitHub Desktop.
Save gszeliga/6a5fcd0849a70f901dc5 to your computer and use it in GitHub Desktop.
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