DotNext by Roman Sakno

<PackageReference Include="DotNext" Version="3.0.0" />

 Sequence

public static class Sequence
Various methods to work with classes implementing IEnumerable<T> interface.
public struct AsyncGenerator<T> : IAsyncEnumerable<T>

Gets enumerable collection created from generator method.

Represents a wrapped for method TryTake in the form of enumerable collection.

public struct Generator<T>

Gets enumerable collection created from generator method.

Wrapped for the enumerator which is limited by count.

public static IEnumerable<T> Append<T>(this IEnumerable<T> collection, T[] items)

Adds items to the end of collection.

public static bool ElementAt<T>(this IEnumerable<T> collection, int index, out T element)

Obtains element at the specified index in the sequence.

public static ValueTask<Optional<T>> ElementAtAsync<T>(this IAsyncEnumerable<T> collection, int index, CancellationToken token = default)

Obtains element at the specified index in the sequence.

public static Optional<T> FirstOrEmpty<T>(this IEnumerable<T> seq)

Obtains first value in the sequence; or None if sequence is empty.

public static Optional<T> FirstOrEmpty<T>(this IEnumerable<T> seq, Predicate<T> filter)

Returns the first element in a sequence that satisfies a specified condition.

public static ValueTask<Optional<T>> FirstOrEmptyAsync<T>(this IAsyncEnumerable<T> seq, CancellationToken token = default)

Obtains first value in the sequence; or None if sequence is empty.

public static ValueTask<Optional<T>> FirstOrEmptyAsync<T>(this IAsyncEnumerable<T> seq, Predicate<T> filter, CancellationToken token = default)

Returns the first element in a sequence that satisfies a specified condition.

public static T? FirstOrNull<T>(this IEnumerable<T> seq) where T : struct

Obtains first value type in the sequence; or null if sequence is empty.

public static ValueTask<T?> FirstOrNullAsync<T>(this IAsyncEnumerable<T> seq, CancellationToken token = default) where T : struct

Obtains first value type in the sequence; or null if sequence is empty.

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

Applies specified action to each collection element.

public static ValueTask ForEachAsync<T>(this IAsyncEnumerable<T> collection, Action<T> action, CancellationToken token = default)

Applies specified action to each collection element asynchronously.

public static ValueTask ForEachAsync<T>(this IAsyncEnumerable<T> collection, Func<T, CancellationToken, ValueTask> action, CancellationToken token = default)

Applies specified action to each collection element asynchronously.

public static ValueTask ForEachAsync<T>(this IEnumerable<T> collection, Func<T, CancellationToken, ValueTask> action, CancellationToken token = default)

Applies the specified asynchronous action to each collection element.

public static IAsyncEnumerator<T> GetAsyncEnumerator<T>(this IEnumerable<T> enumerable, CancellationToken token = default)

Obtains asynchronous enumerator over the sequence of elements.

public static ConsumingEnumerable<T> GetConsumer<T>(this IProducerConsumerCollection<T> collection)

Gets consumer of thread-safe concurrent collection.

public static LimitedEnumerator<T> Limit<T>(this IEnumerator<T> enumerator, int count, bool leaveOpen = false)

Limits the number of the elements in the sequence.

public static IEnumerable<T> Prepend<T>(this IEnumerable<T> collection, T[] items)

Adds items to the beginning of collection.

public static int SequenceHashCode(this IEnumerable<object> sequence, bool salted = true)

Computes hash code for the sequence of objects.

public static IEnumerable<T> Singleton<T>(T item)

Constructs a sequence from the single element.

public static bool Skip<T>(this IEnumerator<T> enumerator, int count)

Bypasses a specified number of elements in a sequence.

public static bool Skip<TEnumerator, T>(this ref TEnumerator enumerator, int count) where TEnumerator : struct, IEnumerator<T>

Bypasses a specified number of elements in a sequence.

public static ValueTask<bool> SkipAsync<T>(this IAsyncEnumerator<T> enumerator, int count)

Bypasses a specified number of elements in a sequence.

public static IAsyncEnumerable<T> SkipNulls<T>(this IAsyncEnumerable<T> collection)

Skip null values in the collection.

public static IEnumerable<T> SkipNulls<T>(this IEnumerable<T> collection)

Skip null values in the collection.

public static Task<T[]> ToArrayAsync<T>(this IAsyncEnumerable<T> collection, int initialCapacity = 10, MemoryAllocator<T> allocator = null, CancellationToken token = default)

Converts asynchronous collection to the array.

public static IAsyncEnumerable<T> ToAsyncEnumerable<T>(this IEnumerable<T> enumerable)

Converts synchronous collection of elements to asynchronous.

public static AsyncGenerator<T> ToAsyncEnumerable<T>(this Func<CancellationToken, ValueTask<Optional<T>>> generator)

Converts generator function to enumerable collection.

public static Generator<T> ToEnumerable<T>(this Func<Optional<T>> generator)

Converts generator function to enumerable collection.

public static IEnumerator<T> ToEnumerator<T>(ReadOnlyMemory<T> memory)

Gets enumerator over all elements in the memory.

public static string ToString<T>(this IEnumerable<T> collection, string delimiter, string ifEmpty = "")

Concatenates each element from the collection into single string.