And or pipes
In order to connect multiple pipes using Boolean logic there are two FilterPipe
pipes called AndFilterPipe<S>
and OrFilterPipe<S>
. These pipes take an object of type S
and emit an object of type S
. However, they only emit the S
object if the collection of IPipe<S, Boolean>
pipes that they wrap return true
. For AndFilterPipe
to emit its incoming S
object, all of its wrapped pipes must return true
that S
object. For the OrFilterPipe
, only one of its wrapped pipes must return true
.
If you want to see if a number is greater than or equal to 1 and less than 10, then use the following AndFilterPipe
.
var _PipeA = new ObjectFilterPipe<Int32>(1, ComparisonFilter.GREATER_THAN_EQUAL);
var _PipeB = new ObjectFilterPipe<Int32>(10, ComparisonFilter.LESS_THAN);
var _ANDPipe = new AndFilterPipe<Int32>(new HasNextPipe<Int32>(_PipeA), new HasNextPipe<Int32>(_PipeB));
_ANDPipe.SetSourceCollection(new List<Int32>() {1, 22, 10, 136, 7, 2, 67 });
while(_ANDPipe.MoveNext())
{
Console.WriteLine(_ANDPipe.Current + "...");
}
The console output of the previous code is as follows:
1...7...2...
Note the use of HasNextPipe<S>
which implements IPipe<S, Boolean>
. If the ObjectFilterPipe
pipes that compose the AndFilterPipe
filter their incoming S
object, then they will return false on a call to MoveNext()
. Thus, HasNextPipe
is useful for determining if a filter pipe has filtered an object.