Remotely/Shared/Extensions/IEnumerableExtensions.cs

34 lines
746 B
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Remotely.Shared.Extensions;
public static class IEnumerableExtensions
{
public static async IAsyncEnumerable<T> ToAsyncEnumerable<T>(this IEnumerable<T> source)
{
foreach (var item in source)
{
yield return item;
await Task.Yield();
}
}
public static int IndexWhere<T>(this IEnumerable<T> source, Func<T, bool> predicate)
{
var index = 0;
foreach (var item in source)
{
if (predicate(item))
{
return index;
}
index++;
}
return -1;
}
}