ExperimentalEnumerableMemoizeT Method

Creates a sequence that lazily caches the source as it is iterated for the first time, reusing the cache thereafter for future re-iterations. If the source is already cached or buffered then it is returned verbatim.

Definition

Namespace: MoreLinq.Experimental
Assembly: MoreLinq (in MoreLinq.dll) Version: 3.4.0+b99a6a8cc504caf2d48372fe54a2f8116c59cd0c
C#
public static IEnumerable<T> Memoize<T>(
	this IEnumerable<T> source
)

Parameters

source  IEnumerableT
The source sequence.

Type Parameters

T
Type of elements in source.

Return Value

IEnumerableT
Returns a sequence that corresponds to a cached version of the input sequence.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IEnumerableT. 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

The returned IEnumerableT will cache items from source in a thread-safe manner. Each thread can call its GetEnumerator to acquire an iterator but the same iterator should not be used simultaneously from multiple threads. The sequence supplied in source is not expected to be thread-safe but it is required to be thread-agnostic because different threads (though never simultaneously) may iterate over the sequence.

Exceptions

See Also