Method PadStart
View SourcePadStart<TSource>(IAsyncEnumerable<TSource>, int)
Pads a sequence with default values in the beginning if it is narrower (shorter in length) than a given width.
Declaration
public static IAsyncEnumerable<TSource?> PadStart<TSource>(this IAsyncEnumerable<TSource> source, int width)
Parameters
Type | Name | Description |
---|---|---|
IAsyncEnumerable<TSource> | source | The sequence to pad. |
int | width | The width/length below which to pad. |
Returns
Type | Description |
---|---|
IAsyncEnumerable<TSource> | Returns a sequence that is at least as wide/long as the width/length
specified by the |
Type Parameters
Name | Description |
---|---|
TSource | The type of the elements of |
Remarks
This operator uses deferred execution and streams its results.
Examples
int[] numbers = { 123, 456, 789 };
var result = numbers.PadStart(5);
The <code>result</code> variable will contain <code>{ 0, 0, 123, 456, 789 }</code>.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|
PadStart<TSource>(IAsyncEnumerable<TSource>, int, TSource)
Pads a sequence with a given filler value in the beginning if it is narrower (shorter in length) than a given width. An additional parameter specifies the value to use for padding.
Declaration
public static IAsyncEnumerable<TSource> PadStart<TSource>(this IAsyncEnumerable<TSource> source, int width, TSource padding)
Parameters
Type | Name | Description |
---|---|---|
IAsyncEnumerable<TSource> | source | The sequence to pad. |
int | width | The width/length below which to pad. |
TSource | padding | The value to use for padding. |
Returns
Type | Description |
---|---|
IAsyncEnumerable<TSource> | Returns a sequence that is at least as wide/long as the width/length
specified by the |
Type Parameters
Name | Description |
---|---|
TSource | The type of the elements of |
Remarks
This operator uses deferred execution and streams its results.
Examples
int[] numbers = { 123, 456, 789 };
var result = numbers.PadStart(5, -1);
The <code>result</code> variable will contain <code>{ -1, -1, 123, 456, 789 }</code>.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|
PadStart<TSource>(IAsyncEnumerable<TSource>, int, Func<int, TSource>)
Pads a sequence with a dynamic filler value in the beginning if it is narrower (shorter in length) than a given width. An additional parameter specifies the function to calculate padding.
Declaration
public static IAsyncEnumerable<TSource> PadStart<TSource>(this IAsyncEnumerable<TSource> source, int width, Func<int, TSource> paddingSelector)
Parameters
Type | Name | Description |
---|---|---|
IAsyncEnumerable<TSource> | source | The sequence to pad. |
int | width | The width/length below which to pad. |
Func<int, TSource> | paddingSelector | Function to calculate padding given the index of the missing element. |
Returns
Type | Description |
---|---|
IAsyncEnumerable<TSource> | Returns a sequence that is at least as wide/long as the width/length
specified by the |
Type Parameters
Name | Description |
---|---|
TSource | The type of the elements of |
Remarks
This operator uses deferred execution and streams its results.
Examples
int[] numbers = { 123, 456, 789 };
var result = numbers.PadStart(6, i => -i);
The <code>result</code> variable will contain <code>{ 0, -1, -2, 123, 456, 789 }</code>.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|