TPL Dataflow provides a TransformBlock
for transforming input, e.g.:
var tb = new TransformBlock<int, int>(i => i * 2);
Is it possible to not output some of the input, e.g. if the input fails some validation test?
var tb = new TransformBlock<InputType, OutputType>(i =>
{
if (!ValidateInput(i))
{
// Do something to not output anything for this input
}
// Normal output
}
If that is not possible, what would be the best pattern to achieve that end?
Something like the following?
BufferBlock<OutputType> output = new BufferBlock<OutputType>();
var ab = new ActionBlock<InputType>(i =>
{
if (ValidateInput(i))
{
output.Post(MyTransform(i));
}
}