Performs a pre-scan (exclusive prefix sum) on a sequence of elements.
Namespace: MoreLinqMoreLinq (in MoreLinq.dll) Version: 3.0.0
Syntaxpublic static IEnumerable<TSource> PreScan<TSource>( this IEnumerable<TSource> source, Func<TSource, TSource, TSource> transformation, TSource identity )
<ExtensionAttribute> Public Shared Function PreScan(Of TSource) ( source As IEnumerable(Of TSource), transformation As Func(Of TSource, TSource, TSource), identity As TSource ) As IEnumerable(Of TSource)
public: [ExtensionAttribute] generic<typename TSource> static IEnumerable<TSource>^ PreScan( IEnumerable<TSource>^ source, Func<TSource, TSource, TSource>^ transformation, TSource identity )
[<ExtensionAttribute>] static member PreScan : source : IEnumerable<'TSource> * transformation : Func<'TSource, 'TSource, 'TSource> * identity : 'TSource -> IEnumerable<'TSource>Parameters
Type:
IEnumerableTSourceThe scanned sequence
Usage NoteIn Visual Basic and C#, you can call this method as an instance method on any object of type
IEnumerableTSource. 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).
RemarksAn exclusive prefix sum returns an equal-length sequence where the N-th element is the sum of the first N-1 input elements (the first element is a special case, it is set to the identity). More generally, the pre-scan allows any commutative binary operation, not just a sum. The inclusive version of PreScan is
ScanTSource(IEnumerableTSource, FuncTSource, TSource, TSource). This operator uses deferred execution and streams its result.
Examplesint[] values = { 1, 2, 3, 4 }; var prescan = values.PreScan((a, b) => a + b, 0); var scan = values.Scan((a, b) => a + b); var result = values.EquiZip(prescan, ValueTuple.Create);prescan
will yield
{ 0, 1, 3, 6 }, while
scanand
resultwill both yield
{ 1, 3, 6, 10 }. This shows the relationship between the inclusive and exclusive prefix sum.
See AlsoRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4