main
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4
 5namespace gorilla.commons.utility
 6{
 7    static public class EnumerableExtensions
 8    {
 9        static public IEnumerable<T> where<T>(this IEnumerable<T> items, Func<T, bool> condition_is_met)
10        {
11            return null == items ? Enumerable.Empty<T>() : items.Where(condition_is_met);
12        }
13
14        static public IList<T> databind<T>(this IEnumerable<T> items_to_bind_to)
15        {
16            return null == items_to_bind_to ? new List<T>() : items_to_bind_to.ToList();
17        }
18
19        static public IEnumerable<T> sorted_using<T>(this IEnumerable<T> items_to_sort, IComparer<T> sorting_algorithm)
20        {
21            var sorted_items = new List<T>(items_to_sort);
22            sorted_items.Sort(sorting_algorithm);
23            return sorted_items;
24        }
25
26        static public IEnumerable<T> all<T>(this IEnumerable<T> items)
27        {
28            foreach (var item in items ?? Enumerable.Empty<T>()) yield return item;
29        }
30
31        static public void each<T>(this IEnumerable<T> items, Action<T> action)
32        {
33            foreach (var item in items ?? Enumerable.Empty<T>()) action(item);
34        }
35
36        static public IEnumerable<T> join_with<T>(this IEnumerable<T> left, IEnumerable<T> right)
37        {
38            if (null == right) return left;
39
40            var list = new List<T>();
41            list.AddRange(left);
42            list.AddRange(right);
43            return list;
44        }
45    }
46}