io.vlingo.reactivestreams.Operator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vlingo-streams Show documentation
Show all versions of vlingo-streams Show documentation
Reactive Streams for the VLINGO XOOM Platform.
// Copyright © 2012-2020 VLINGO LABS. All rights reserved.
//
// This Source Code Form is subject to the terms of the
// Mozilla Public License, v. 2.0. If a copy of the MPL
// was not distributed with this file, You can obtain
// one at https://mozilla.org/MPL/2.0/.
package io.vlingo.reactivestreams;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import io.vlingo.reactivestreams.operator.Filter;
import io.vlingo.reactivestreams.operator.Mapper;
/**
* An operator that takes {@code T} input and produces {@code R} output
* into a given {@code Consumer}.
* @param the input parameter type
* @param the result type
*/
public interface Operator {
/**
* Answer a new {@code Operator} that filters using {@code filter}.
* @param filter the {@code Predicate} that filters
* @param the type of values to filter
* @return {@code Operator}
*/
static Operator filterWith(final Predicate filter) {
return new Filter<>(filter);
}
/**
* Answer a new {@code Operator} that maps from values of {@code T}
* to values of {@code R} by means of the {@code mapper}.
* @param mapper the {@code Function} that maps from values of T to values of R
* @param the type of values to mapped from
* @param the type of values mapped to
* @return {@code Operator}
*/
static Operator mapWith(final Function mapper) {
return new Mapper<>(mapper);
}
/**
* Accept the {@code T} value and potentially give an
* {@code R} outcome to the {@code consumer}.
* @param value the T value to accept
* @param consumer the {@code Consumer} that may receive the outcome.
*/
void performInto(final T value, final Consumer consumer);
}