com.github.dm.jrt.function.FunctionalRoutine Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jroutine Show documentation
Show all versions of jroutine Show documentation
Parallel programming on the go
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.dm.jrt.function;
import com.github.dm.jrt.builder.ConfigurableBuilder;
import com.github.dm.jrt.channel.ResultChannel;
import com.github.dm.jrt.invocation.FilterInvocation;
import com.github.dm.jrt.routine.Routine;
import org.jetbrains.annotations.NotNull;
import java.util.List;
/**
* Interface defining a functional routine, that is, a routine concatenating map and reduce
* functions.
* Each function in the channel is backed by a sub-routine instance, that can have its own specific
* configuration and invocation mode.
*
* Note that, if at least one reduce function is part of the concatenation, the results will be
* propagated only when the invocation completes.
*
* Created by davide-maestroni on 10/16/2015.
*
* @param the input data type.
* @param the output data type.
*/
public interface FunctionalRoutine
extends Routine, ConfigurableBuilder> {
/**
* Concatenates a functional routine based on the specified accumulate function to this one.
*
* The output will be accumulated as follows:
*
*
*
* acc = function.apply(acc, input);
*
*
* The accumulated value will be passed as result only when the routine invocation completes.
*
* Note that the created routine will be invoked in an asynchronous mode.
*
* @param function the bi-function instance.
* @return the concatenated functional routine.
*/
@NotNull
FunctionalRoutine thenAsyncAccumulate(
@NotNull BiFunction super OUT, ? super OUT, ? extends OUT> function);
/**
* Concatenates a functional routine based on the specified predicate to this ones.
* The output will be filtered according to the result returned by the predicate.
*
* Note that the created routine will be invoked in an asynchronous mode.
*
* @param predicate the predicate instance.
* @return the concatenated functional routine.
*/
@NotNull
FunctionalRoutine thenAsyncFilter(@NotNull Predicate super OUT> predicate);
/**
* Concatenates a functional routine based on the specified consumer to this one.
*
* Note that the created routine will be invoked in an asynchronous mode.
*
* @param consumer the bi-consumer instance.
* @param the concatenation output type.
* @return the concatenated functional routine.
*/
@NotNull
FunctionalRoutine thenAsyncMap(
@NotNull BiConsumer super OUT, ? super ResultChannel> consumer);
/**
* Concatenates a functional routine based on the specified invocation to this one.
*
* Note that the created routine will be invoked in an asynchronous mode.
*
* @param invocation the filter invocation instance.
* @param the concatenation output type.
* @return the concatenated functional routine.
*/
@NotNull
FunctionalRoutine thenAsyncMap(
@NotNull FilterInvocation super OUT, AFTER> invocation);
/**
* Concatenates a functional routine based on the specified function to this one.
*
* Note that the created routine will be invoked in an asynchronous mode.
*
* @param function the function instance.
* @param the concatenation output type.
* @return the concatenated functional routine.
*/
@NotNull
FunctionalRoutine thenAsyncMap(
@NotNull Function super OUT, AFTER> function);
/**
* Concatenates a functional routine based on the specified instance to this one.
*
* Note that the passed routine will be invoked in an asynchronous mode.
*
* @param routine the routine instance.
* @param the concatenation output type.
* @return the concatenated functional routine.
*/
@NotNull
FunctionalRoutine thenAsyncMap(@NotNull Routine super OUT, AFTER> routine);
/**
* Concatenates a functional routine based on the specified reducing consumer to this one.
* The outputs will be reduced by applying the function, only when the routine invocation
* completes.
*
* Note that the created routine will be invoked in an asynchronous mode.
*
* @param consumer the bi-consumer instance.
* @param the concatenation output type.
* @return the concatenated functional routine.
*/
@NotNull
FunctionalRoutine thenAsyncReduce(
@NotNull BiConsumer super List extends OUT>, ? super ResultChannel>
consumer);
/**
* Concatenates a functional routine based on the specified reducing function to this one.
* The outputs will be reduced by applying the function, only when the routine invocation
* completes.
*
* Note that the created routine will be invoked in an asynchronous mode.
*
* @param function the function instance.
* @param the concatenation output type.
* @return the concatenated functional routine.
*/
@NotNull
FunctionalRoutine thenAsyncReduce(
@NotNull Function super List extends OUT>, AFTER> function);
/**
* Lifts this functional routine by applying the specified function.
*
* @param function the function instance.
* @param the lifting input type.
* @param the lifting output type.
* @return the lifted functional routine.
*/
@NotNull
FunctionalRoutine thenFlatLift(
@NotNull Function super FunctionalRoutine, ? extends
FunctionalRoutine> function);
/**
* Lifts this functional routine by applying the specified function.
*
* @param function the function instance.
* @param the lifting input type.
* @param the lifting output type.
* @return the lifted functional routine.
*/
@NotNull
FunctionalRoutine thenLift(
@NotNull Function super FunctionalRoutine, ? extends Routine> function);
/**
* Concatenates a functional routine based on the specified predicate to this ones.
* The output will be filtered according to the result returned by the predicate.
*
* Note that the created routine will be invoked in a parallel mode.
*
* @param predicate the predicate instance.
* @return the concatenated functional routine.
*/
@NotNull
FunctionalRoutine thenParallelFilter(@NotNull Predicate super OUT> predicate);
/**
* Concatenates a functional routine based on the specified consumer to this one.
*
* Note that the created routine will be invoked in a parallel mode.
*
* @param consumer the bi-consumer instance.
* @param the concatenation output type.
* @return the concatenated functional routine.
*/
@NotNull
FunctionalRoutine thenParallelMap(
@NotNull BiConsumer super OUT, ? super ResultChannel> consumer);
/**
* Concatenates a functional routine based on the specified invocation to this one.
*
* Note that the created routine will be invoked in a parallel mode.
*
* @param invocation the filter invocation instance.
* @param the concatenation output type.
* @return the concatenated functional routine.
*/
@NotNull
FunctionalRoutine thenParallelMap(
@NotNull FilterInvocation super OUT, AFTER> invocation);
/**
* Concatenates a functional routine based on the specified function to this one.
*
* Note that the created routine will be invoked in a parallel mode.
*
* @param function the function instance.
* @param the concatenation output type.
* @return the concatenated functional routine.
*/
@NotNull
FunctionalRoutine thenParallelMap(
@NotNull Function super OUT, AFTER> function);
/**
* Concatenates a functional routine based on the specified instance to this one.
*
* Note that the passed routine will be invoked in a parallel mode.
*
* @param routine the routine instance.
* @param the concatenation output type.
* @return the concatenated functional routine.
*/
@NotNull
FunctionalRoutine thenParallelMap(
@NotNull Routine super OUT, AFTER> routine);
/**
* Concatenates a functional routine based on the specified accumulate function to this one.
*
* The output will be accumulated as follows:
*
*
*
* acc = function.apply(acc, input);
*
*
* The accumulated value will be passed as result only when the routine invocation completes.
*
* Note that the created routine will be invoked in a synchronous mode.
*
* @param function the bi-function instance.
* @return the concatenated functional routine.
*/
@NotNull
FunctionalRoutine thenSyncAccumulate(
@NotNull BiFunction super OUT, ? super OUT, ? extends OUT> function);
/**
* Concatenates a functional routine based on the specified predicate to this ones.
* The output will be filtered according to the result returned by the predicate.
*
* Note that the created routine will be invoked in a synchronous mode.
*
* @param predicate the predicate instance.
* @return the concatenated functional routine.
*/
@NotNull
FunctionalRoutine thenSyncFilter(@NotNull Predicate super OUT> predicate);
/**
* Concatenates a functional routine based on the specified consumer to this one.
*
* Note that the created routine will be invoked in a synchronous mode.
*
* @param consumer the bi-consumer instance.
* @param the concatenation output type.
* @return the concatenated functional routine.
*/
@NotNull
FunctionalRoutine thenSyncMap(
@NotNull BiConsumer super OUT, ? super ResultChannel> consumer);
/**
* Concatenates a functional routine based on the specified invocation to this one.
*
* Note that the created routine will be invoked in a synchronous mode.
*
* @param invocation the filter invocation instance.
* @param the concatenation output type.
* @return the concatenated functional routine.
*/
@NotNull
FunctionalRoutine thenSyncMap(
@NotNull FilterInvocation super OUT, AFTER> invocation);
/**
* Concatenates a functional routine based on the specified function to this one.
*
* Note that the created routine will be invoked in a synchronous mode.
*
* @param function the function instance.
* @param the concatenation output type.
* @return the concatenated functional routine.
*/
@NotNull
FunctionalRoutine thenSyncMap(
@NotNull Function super OUT, AFTER> function);
/**
* Concatenates a functional routine based on the specified instance to this one.
*
* Note that the passed routine will be invoked in a synchronous mode.
*
* @param routine the routine instance.
* @param the concatenation output type.
* @return the concatenated functional routine.
*/
@NotNull
FunctionalRoutine thenSyncMap(@NotNull Routine super OUT, AFTER> routine);
/**
* Concatenates a functional routine based on the specified reducing consumer to this one.
* The outputs will be reduced by applying the function, only when the routine invocation
* completes.
*
* Note that the created routine will be invoked in a synchronous mode.
*
* @param consumer the bi-consumer instance.
* @param the concatenation output type.
* @return the concatenated functional routine.
*/
@NotNull
FunctionalRoutine thenSyncReduce(
@NotNull BiConsumer super List extends OUT>, ? super ResultChannel>
consumer);
/**
* Concatenates a functional routine based on the specified reducing function to this one.
* The outputs will be reduced by applying the function, only when the routine invocation
* completes.
*
* Note that the created routine will be invoked in a synchronous mode.
*
* @param function the function instance.
* @param the concatenation output type.
* @return the concatenated functional routine.
*/
@NotNull
FunctionalRoutine thenSyncReduce(
@NotNull Function super List extends OUT>, AFTER> function);
}