Table of Contents

Class EnumerableExtensions

Namespace
Olve.Utilities.CollectionExtensions
Assembly
Olve.Utilities.dll

Provides extension methods for enumerables.

public static class EnumerableExtensions
Inheritance
EnumerableExtensions
Inherited Members

Methods

ForEach<T>(IEnumerable<T>, Action<T>)

Performs an action on each item in the enumerable.

public static void ForEach<T>(this IEnumerable<T> enumerable, Action<T> action)

Parameters

enumerable IEnumerable<T>

The enumerable to perform the action on.

action Action<T>

The action to perform on each item.

Type Parameters

T

The type of the items in the enumerable.

Remarks

Please note that this method is not lazy and will execute the action on each item immediately.

ForEach<TIn, TOut>(IEnumerable<TIn>, Func<TIn, TOut>)

Performs an action on each item in the enumerable.

public static IEnumerable<TOut> ForEach<TIn, TOut>(this IEnumerable<TIn> enumerable, Func<TIn, TOut> action)

Parameters

enumerable IEnumerable<TIn>

The enumerable to perform the action on.

action Func<TIn, TOut>

The action to perform on each item.

Returns

IEnumerable<TOut>

An enumerable of the results of the action.

Type Parameters

TIn

The type of the items in the enumerable.

TOut

The type of the items in the resulting enumerable.

Remarks

Please note that this method is lazy and will not execute the action on each item until the enumerable is enumerated.

Product(IEnumerable<float>)

Returns the product of all the items in the enumerable.

public static float Product(this IEnumerable<float> enumerable)

Parameters

enumerable IEnumerable<float>

The enumerable to calculate the product of.

Returns

float

The product of all the items in the enumerable.

TryAsReadOnlySet<T>(IEnumerable<T>, out IReadOnlySet<T>?)

Attempts to cast an IEnumerable<T> to an IReadOnlySet<T>.

public static bool TryAsReadOnlySet<T>(this IEnumerable<T> enumerable, out IReadOnlySet<T>? readOnlySet)

Parameters

enumerable IEnumerable<T>

The enumerable to attempt to cast.

readOnlySet IReadOnlySet<T>

When this method returns, contains the resulting IReadOnlySet<T> if the cast was successful, or null otherwise.

Returns

bool

true if the cast was successful; otherwise, false.

Type Parameters

T

The type of elements in the collection.

TryAsSet<T>(IEnumerable<T>, out ISet<T>?)

Attempts to cast an IEnumerable<T> to an ISet<T>.

public static bool TryAsSet<T>(this IEnumerable<T> enumerable, out ISet<T>? set)

Parameters

enumerable IEnumerable<T>

The enumerable to attempt to cast.

set ISet<T>

When this method returns, contains the resulting ISet<T> if the cast was successful, or null otherwise.

Returns

bool

true if the cast was successful; otherwise, false.

Type Parameters

T

The type of elements in the collection.