This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//What we're gonna do with the async text when available | |
Partial<Builder> textToApply = | |
sources.value(textf) | |
.by((builder, text) -> builder.flatMapR(b -> text.mapR(b::text))); | |
//Same thing for the number | |
Partial<Builder> numberToApply = | |
sources.value(numberf) | |
.by((builder, number) -> builder.flatMapR(b -> number.mapR(b::number))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CompositionSources<Builder> sources = CompositionSources.stickedTo(Builder.class); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class CompositionSources<B> | |
{ | |
private CompositionSources(){ } | |
public interface Partial<B> | |
{ | |
CompletableFuture<Outcome<B>> apply(CompletableFuture<Outcome<B>> b); | |
} | |
public interface MergingStage<B, V>{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Builder implements WannabeApplicative<Message> { | |
private String _text; | |
private Integer _number; | |
public Builder text(String text){ | |
_text=text; | |
return this; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Message{ | |
private final String _text; | |
private final Integer _number; | |
private Message(String msg, Integer number){ | |
_text = msg; | |
_number = number; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CompletableFuture<Outcome<String>> textf = | |
completedFuture(maybe("And the number is %s!")); | |
CompletableFuture<Outcome<Integer>> numberf = | |
completedFuture(maybe(22)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Acceptance validation on the range of data being requested | |
acceptableInterval(from, to, DeviceParameters.from(paramId).getResolution()) | |
.fold( | |
failure -> asyncResponse | |
.resume(status(422) | |
.entity(asErrorReply(failure)) | |
.build()) | |
, | |
accepted -> runAsync(() -> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Outcome<TariffStructure> tariff = | |
maybe(ctx.getTariffStructureService() | |
.flatMap(ts -> ts.get(ctx.getPrices().getTariffId()))) | |
.orIfEmpty(() -> fail(format("Tariff structure with id '%d' could not be found", ctx.getPrices().getTariffId()))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Either; | |
import lombok.AccessLevel; | |
import lombok.AllArgsConstructor; | |
import lombok.NoArgsConstructor; | |
import lombok.ToString; | |
import java.util.*; | |
import java.util.function.BiFunction; | |
import java.util.function.Function; | |
import java.util.function.Supplier; |