public static int Find <TSource>(IEnumerable <TSource> source, Func <TSource, bool> predicate)
        {
            var _index = -1;

            EnumerableUtil.First(source, x => {
                _index++;
                return(predicate(x));
            });

            return(_index);
        }
        public static IEnumerable <TSource> Distinct <TSource>(IEnumerable <TSource> source, IEqualityComparer <TSource> comparer = null)
        {
            var _result = new List <TSource>();

            EnumerableUtil.Each(source, x => {
                if (EnumerableUtil.FirstOrDefault(_result, y => comparer != null ? comparer.Equals(x, y) : x.Equals(y)) == null)
                {
                    _result.Add(x);
                }
            });
            return(_result);
        }
        public static int Find <TSource>(IEnumerable <TSource> source, Func <TSource, bool> predicate, int defaultValue)
        {
            var _index = -1;

            if (EnumerableUtil.FirstOrDefault(source, x => {
                _index++;
                return(predicate(x));
            }) == null)
            {
                return(defaultValue);
            }

            return(_index);
        }
        private static IEnumerable <TSource> OrderBy <TSource>(IEnumerable <TSource> source, ICollection <Comparison <TSource> > comparisons)
        {
            var _result = EnumerableUtil.ToList(source);

            _result.Sort((x, y) => {
                foreach (var _comparison in comparisons)
                {
                    var _order = _comparison(x, y);
                    if (_order != 0)
                    {
                        return(_order);
                    }
                }
                return(0);
            });
            return(_result);
        }
 IEnumerator IEnumerable.GetEnumerator()
 {
     return(EnumerableUtil.OrderBy(this._source, this._comparisons).GetEnumerator());
 }
 public static IEnumerable <TSource> Union <TSource>(IEnumerable <TSource> first, IEnumerable <TSource> second, IEqualityComparer <TSource> comparer = null)
 {
     return(EnumerableUtil.Distinct(EnumerableUtil.UnionAll(first, second), comparer));
 }
 public static IEnumerable <TSource> Except <TSource>(IEnumerable <TSource> first, IEnumerable <TSource> second, IEqualityComparer <TSource> comparer = null)
 {
     return(EnumerableUtil.Where(first, x => EnumerableUtil.FirstOrDefault(second, y => comparer != null ? comparer.Equals(x, y) : x.Equals(y)) == null));
 }
 public static IEnumerable <TResult> Join <TOuter, TInner, TKey, TResult>(IEnumerable <TOuter> outer, IEnumerable <TInner> inner, Func <TOuter, TKey> outerKeySelector, Func <TInner, TKey> innerKeySelector, Func <TOuter, TInner, TResult> resultSelector) where TKey : IComparable <TKey>
 {
     return(EnumerableUtil.SelectMany(outer, o => EnumerableUtil.Select(
                                          EnumerableUtil.Where(inner, i => outerKeySelector(o).CompareTo(innerKeySelector(i)) == 0),
                                          i => resultSelector(o, i))));
 }
 public static TSource[] ToArray <TSource>(IEnumerable <TSource> source)
 {
     return(EnumerableUtil.ToList(source).ToArray());
 }
 public static int Count <TSource>(IEnumerable <TSource> source)
 {
     return(EnumerableUtil.Count(source, x => true));
 }