All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.occurrent.application.composition.command.CommandConversion Maven / Gradle / Ivy

There is a newer version: 0.19.5
Show newest version
package org.occurrent.application.composition.command;

import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Utility functions to convert functions expecting a list of domain events into a functions expecting a stream of domain events,
 * and vice versa.
 */
public class CommandConversion {

    /**
     * Convert a command taking Stream<T> into one that takes a List<T>.
     *
     * @param command The command to convert
     * @param      The type of the domain event
     * @return A function that does the conversion described above.
     */
    public static  Function, List> toListCommand(Function, Stream> command) {
        return events -> command.apply(events.stream()).collect(Collectors.toList());
    }

    /**
     * Convert a command taking List<T> into one that takes a Stream<T>.
     *
     * @param command The command to convert
     * @param      The type of the domain event
     * @return A function that does the conversion described above.
     */
    public static  Function, Stream> toStreamCommand(Function, List> command) {
        return events -> command.apply(events.collect(Collectors.toList())).stream();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy