< Summary

Information
Class: MoreStructures.Utilities.ValueEnumerableExtensions
Assembly: MoreStructures
File(s): /home/runner/work/MoreStructures/MoreStructures/MoreStructures/Utilities/ValueEnumerableExtensions.cs
Line coverage
100%
Covered lines: 3
Uncovered lines: 0
Coverable lines: 3
Total lines: 29
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
AsValue(...)100%2100%

File(s)

/home/runner/work/MoreStructures/MoreStructures/MoreStructures/Utilities/ValueEnumerableExtensions.cs

#LineLine coverage
 1namespace MoreStructures.Utilities;
 2
 3/// <summary>
 4/// Extension methods for <see cref="IValueEnumerable{T}"/>.
 5/// </summary>
 6public static class ValueEnumerableExtensions
 7{
 8    /// <summary>
 9    /// Wraps the provided <paramref name="enumerable"/> into a <see cref="IValueEnumerable{T}"/>, which uses
 10    /// <see cref="Enumerable.SequenceEqual{TSource}(IEnumerable{TSource}, IEnumerable{TSource})"/> to check
 11    /// for equality.
 12    /// </summary>
 13    /// <typeparam name="T">The type of objects of <paramref name="enumerable"/>.</typeparam>
 14    /// <param name="enumerable">The enumerable to wrap.</param>
 15    /// <returns>A <see cref="IValueEnumerable{T}"/> wrapping the provided <see cref="IEnumerable{T}"/>.</returns>
 16    /// <remarks>
 17    /// Useful to preserve equality by value in records and other value structures which contain enumerable objects.
 18    /// <br/>
 19    /// Passing a <see cref="string"/> as <paramref name="enumerable"/> will result in the instantiation of a
 20    /// specialized concretion of <see cref="IValueEnumerable{T}"/> which handles strings specifically:
 21    /// <see cref="StringValueEnumerable"/>.
 22    /// <br/>
 23    /// Time and Space Complexity are O(1), as this method doesn't iterate over <paramref name="enumerable"/>.
 24    /// </remarks>
 25    public static IValueEnumerable<T> AsValue<T>(this IEnumerable<T> enumerable) =>
 1605326        enumerable is string str
 1605327        ? (IValueEnumerable<T>)new StringValueEnumerable(str)
 1605328        : new ValueEnumerable<T>(enumerable);
 29}