MoreEnumerable.Scan<TSource> Method (IEnumerable<TSource>, Func<TSource, TSource, TSource>) |
Peforms a scan (inclusive prefix sum) on a sequence of elements.
Namespace:
MoreLinq
Assembly:
MoreLinq (in MoreLinq.dll) Version: 2.7.0
Syntaxpublic static IEnumerable<TSource> Scan<TSource>(
this IEnumerable<TSource> source,
Func<TSource, TSource, TSource> transformation
)
<ExtensionAttribute>
Public Shared Function Scan(Of TSource) (
source As IEnumerable(Of TSource),
transformation As Func(Of TSource, TSource, TSource)
) As IEnumerable(Of TSource)
public:
[ExtensionAttribute]
generic<typename TSource>
static IEnumerable<TSource>^ Scan(
IEnumerable<TSource>^ source,
Func<TSource, TSource, TSource>^ transformation
)
[<ExtensionAttribute>]
static member Scan :
source : IEnumerable<'TSource> *
transformation : Func<'TSource, 'TSource, 'TSource> -> IEnumerable<'TSource>
Parameters
- source
- Type: System.Collections.Generic.IEnumerable<TSource>
Source sequence - transformation
- Type: System.Func<TSource, TSource, TSource>
Transformation operation
Type Parameters
- TSource
- Type of elements in source sequence
Return Value
Type:
IEnumerable<TSource>The scanned sequence
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type
IEnumerable<TSource>. When you use instance method syntax to call this method, omit the first parameter. For more information, see
Extension Methods (Visual Basic) or
Extension Methods (C# Programming Guide).
Remarks
ExamplesFunc<int, int, int> plus = (a, b) => a + b;
int[] values = { 1, 2, 3, 4 };
IEnumerable<int> prescan = values.PreScan(plus, 0);
IEnumerable<int> scan = values.Scan(plus; a + b);
IEnumerable<int> result = values.ZipShortest(prescan, plus);
prescan will yield
{ 0, 1, 3, 6 }, while
scan
and
result will both yield
{ 1, 3, 6, 10 }. This
shows the relationship between the inclusive and exclusive prefix sum.
See Also