Skip navigation links

@CheckReturnValue @ParametersAreNonnullByDefault

Package io.spine.server.tuple

This package provides tuples for return values from command handling or commanding methods.

See: Description

Package io.spine.server.tuple Description

This package provides tuples for return values from command handling or commanding methods.

Although tuples are considered harmful in general, they are useful for describing types of several messages returned by a method. Consider the following example.

The return value of the below method does not say much about the number and types of returned event messages.


     {@literal @}Assign
     List<Message> on(CreateTask cmd) { ... }
 
The below declaration gives both number and types of the events:

     {@literal @}Assign
     Pair<TaskCreated, TaskAssigned> on(CreateTask cmd) { ... }
 

It should re-iterated that the purpose of this package is limited to the scenarios described above. Programmers are strongly discouraged from applying tuples for other purposes.

Generic Types

Classes provided by this package can support up to 5 generic parameters. They are named from <A> through <E>.

The first generic parameter <A> must always be a specific Message class.

Types from <B> through <E> can be either Message or Optional. See sections below for details.

Basic Tuples

The following tuple classes are provided:

Basic tuple classes allow Optional starting from the second generic argument.

Alternatives

In order to define alternatively returned values, please use the following classes:

Generic parameters for alternatives can be only Message.

We believe that a list of alternatives longer than five is hard to understand. If you face a such a need, consider splitting a command into two or more independent commands so that their outcome is more obvious.

Using Tuples with Alternatives

A Pair can be defined with the second parameter being on of the Either subclasses, and created using Pair.withEither().

Skip navigation links