Code/EnumerableExtensions.cs
using System;
using System.Collections.Generic;
namespace ExtendedCollections;
public static class EnumerableExtensions
{
public static IEnumerable<TResult> Combine<TResult, T1, T2>(this IEnumerable<T1> @this, IEnumerable<T2> other, Func<T1, T2, TResult> combiner)
{
foreach(var value1 in @this)
{
foreach(var value2 in other)
{
yield return combiner.Invoke(value1, value2);
}
}
}
public static int IndexOf<T>(this IEnumerable<T> enumerable, T item)
{
if(enumerable is IList<T> list)
return list.IndexOf(item);
if(enumerable is string str && item is char ch)
return str.IndexOf(ch);
int i = 0;
foreach(var value in enumerable)
{
if(Equals(value, item))
return i;
++i;
}
return -1;
}
}