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.
Namespace:
MoreLinq.Experimental
Assembly:
MoreLinq (in MoreLinq.dll) Version: 3.0.0
Syntax public static IEnumerable<T> Memoize<T>(
this IEnumerable<T> source
)
<ExtensionAttribute>
Public Shared Function Memoize(Of T) (
source As IEnumerable(Of T)
) As IEnumerable(Of T)
public:
[ExtensionAttribute]
generic<typename T>
static IEnumerable<T>^ Memoize(
IEnumerable<T>^ source
)
[<ExtensionAttribute>]
static member Memoize :
source : IEnumerable<'T> -> IEnumerable<'T>
Parameters
- source
- Type: System.Collections.GenericIEnumerableT
The source sequence.
Type Parameters
- T
-
Type of elements in source.
Return Value
Type:
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 simultanesouly
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.
See Also