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

com.github.dm.jrt.function.FunctionalRoutine Maven / Gradle / Ivy

There is a newer version: 5.9.0
Show newest version
/*
 * 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 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 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> 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 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 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 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 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, 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, ? 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, ? 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 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> 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 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 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 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 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 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> 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 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 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 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 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, AFTER> function); }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy