
io.vlingo.reactivestreams.operator.Mapper Maven / Gradle / Ivy
// 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.operator;
import java.util.function.Consumer;
import java.util.function.Function;
import io.vlingo.reactivestreams.Operator;
import io.vlingo.reactivestreams.Streams;
/**
* Maps from {@code Sink} to {@code Source}.
* @param the input parameter type
* @param the result type
*/
public class Mapper implements Operator {
private final Function mapper;
public Mapper(final Function mapper) {
this.mapper = mapper;
}
@Override
public void performInto(final T value, Consumer consumer) {
try {
consumer.accept(mapper.apply(value));
} catch (Exception e) {
Streams.logger().error("Mapper failed because: " + e.getMessage(), e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy