| | 1 | | namespace MoreStructures.Utilities; |
| | 2 | |
|
| | 3 | | /// <summary> |
| | 4 | | /// Extension methods for <see cref="IValueEnumerable{T}"/>. |
| | 5 | | /// </summary> |
| | 6 | | public 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) => |
| 16053 | 26 | | enumerable is string str |
| 16053 | 27 | | ? (IValueEnumerable<T>)new StringValueEnumerable(str) |
| 16053 | 28 | | : new ValueEnumerable<T>(enumerable); |
| | 29 | | } |