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

com.github.hakenadu.javalangchains.chains.base.ApplyToStreamInputChain Maven / Gradle / Ivy

package com.github.hakenadu.javalangchains.chains.base;

import java.util.stream.Stream;

import com.github.hakenadu.javalangchains.chains.Chain;

/**
 * this chain applies another chain (which is passed as a constructor parameter)
 * to each item of the input stream.
 *
 * @param  the type of each item in the input stream
 * @param  the type of each item in the output stream
 */
public final class ApplyToStreamInputChain implements Chain, Stream> {

	/**
	 * this chain is applied to each item of the input stream
	 */
	private final Chain applyToStreamItemChain;

	/**
	 * @param applyToStreamItemChain {@link #applyToStreamItemChain}
	 */
	public ApplyToStreamInputChain(final Chain applyToStreamItemChain) {
		this.applyToStreamItemChain = applyToStreamItemChain;
	}

	@Override
	public Stream run(final Stream input) {
		return input.map(this.applyToStreamItemChain::run);
	}
}