using System;
using System.Collections.Generic;
namespace OpenMacroBoard.SDK.Utils
{
///
/// Some LINQ extensions we use internally.
///
public static class LinqExtensions
{
///
///
/// A useful combination of LINQs Select() and Where().
/// Prevents invalid object states between those two calls by combining them.
///
///
/// If the returns (true, value) the value will be yielded.
/// If the returns (false, value) it will not be present in
/// the ouput enumerble.
///
///
/// Input type.
/// Output type.
/// Incomming source enumerable
/// Filter/Selector
public static IEnumerable SelectWhere(
this IEnumerable source,
Func selector
)
{
foreach (var item in source)
{
var (success, output) = selector(item);
if (success)
{
yield return output;
}
}
}
}
}