using System; using System.Collections.Generic; using System.Linq; using EE = System.Collections.Generic.IEnumerable; namespace Gallium { public static class EnumerableEntityExtensions { public static EE ForEachEntity( this EE entities, Func lambda) { return entities .Select( x => !x.Has() || !x.Has() ? x : lambda(x, x.Get(), x.Get())); } public static EE ForEachEntity( this EE entities, Func lambda) { return entities .Select( x => !x.Has() || !x.Has() || !x.Has() ? x : lambda(x, x.Get(), x.Get(), x.Get())); } public static EE ForEntities( this EE entities, Func lambda) { List list = entities.ToList(); EE has = lambda(list.HasComponents()); EE hasNot = list.NotComponents(); return hasNot.Union(has); } public static EE ForEntities( this EE entities, Func lambda) { List list = entities.ToList(); EE has = lambda(list.HasComponents()); EE hasNot = list.NotComponents(); return hasNot.Union(has); } public static EE ForEntities( this EE entities, Func lambda) { List list = entities.ToList(); EE has = lambda(list.HasComponents()); EE hasNot = list.NotComponents(); return hasNot.Union(has); } public static EE HasComponents(this EE entities) { return entities .Where(x => x.Has() && x.Has()); } public static EE HasComponents(this EE entities) { return entities .Where(x => x.Has() && x.Has() && x.Has()); } public static EE HasComponents(this EE entities) { return entities .Where( x => x.Has() && x.Has() && x.Has() && x.Has()); } public static EE NotComponents(this EE entities) { return entities .Where(x => !x.Has() || !x.Has()); } public static EE NotComponents(this EE entities) { return entities .Where(x => !x.Has() || !x.Has() || !x.Has()); } public static EE NotComponents(this EE entities) { return entities .Where( x => !x.Has() || !x.Has() || !x.Has() || !x.Has()); } } }