Method Pipe
| Edit this page View SourcePipe<TSource>(IEnumerable<TSource>, Action<TSource>)
Lazily invokes an action for each value in the sequence.
Declaration
public static IEnumerable<TSource> Pipe<TSource>(this IEnumerable<TSource> source, Action<TSource> action)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<TSource> | source | Source sequence. |
Action<TSource> | action | Action to invoke for each element. |
Returns
Type | Description |
---|---|
IEnumerable<TSource> | Sequence exhibiting the specified side-effects upon enumeration. |
Type Parameters
Name | Description |
---|---|
TSource | Source sequence element type. |
Remarks
This method is a synonym for Do<TSource>(IEnumerable<TSource>, Action<TSource>).
This method uses deferred execution and streams its results.
Examples
The following code example demonstrates how to lazily invoke actions for each element using Do
, which is a synonym for Pipe
.
var sequence = Enumerable.Range(1, 5);
// Execute an action for each element
var result = sequence
.Do(i => Console.Write($"{i}, "));
Console.WriteLine("Before");
result.Consume();
Console.WriteLine("After");
// This code produces the following output:
// Before
// 1, 2, 3, 4, 5, After
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|