Class ListCommandComposition
java.lang.Object
org.occurrent.application.composition.command.ListCommandComposition
Compose several "list commands" (
Function<List<T>, List<T>>) into one by leveraging function composition.
Commands will be executed in left-to-right order, for example:
Function<List<T>, List<T>> domainFunction1 = ..
Function<List<T>, List<T>> domainFunction2 = ..
applicationService.execute("streamid", composeCommands(domainFunction1, domainFunction2));
In this example, domainFunction1 will execute before domainFunction2 and the events returned from domainFunction2
will be appended as input to domainFunction2. All events will then be written atomically to an event store.
Note that in most cases the domain function will not have the form Function<List<T>, List<T>>. You can then
use PartialFunctionApplication to create partially applied functions that you can then compose.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncomposeCommands(Function<List<T>, List<T>> firstCommand, Function<List<T>, List<T>> secondCommand, Function<List<T>, List<T>>... additionalCommands) Compose the supplied commands into a single function.composeCommands(List<Function<List<T>, List<T>>> commands) Compose the supplied list of commands into a single function.composeCommands(Stream<Function<List<T>, List<T>>> commands) Compose the supplied stream of commands into a single function.
-
Constructor Details
-
ListCommandComposition
public ListCommandComposition()
-
-
Method Details
-
composeCommands
@SafeVarargs public static <T> Function<List<T>,List<T>> composeCommands(Function<List<T>, List<T>> firstCommand, Function<List<T>, List<T>> secondCommand, Function<List<T>, List<T>>... additionalCommands) Compose the supplied commands into a single function.- Type Parameters:
T- The domain event type- Parameters:
firstCommand- The first command to composesecondCommand- The second command to composeadditionalCommands- Additional commands to compose- Returns:
- A single function that is a composition of all supplied commands
-
composeCommands
public static <T> Function<List<T>,List<T>> composeCommands(List<Function<List<T>, List<T>>> commands) Compose the supplied list of commands into a single function.- Type Parameters:
T- The domain event type- Parameters:
commands- The commands to compose- Returns:
- A single function that is a composition of all supplied commands
-
composeCommands
public static <T> Function<List<T>,List<T>> composeCommands(Stream<Function<List<T>, List<T>>> commands) Compose the supplied stream of commands into a single function.- Type Parameters:
T- The domain event type- Parameters:
commands- The commands to compose- Returns:
- A single function that is a composition of all supplied commands
-