public static int FindIndex <T>(this IPersistentArray <T> array, Func <T, bool> predicate) { Debug.Assert(array != null); Debug.Assert(predicate != null); return(Enumerable.Range(0, array.Length).First(i => predicate(array[i]))); }
public static IPersistentArray <U> Map <T, U>(this IPersistentArray <T> array, Func <T, U> mapper) { Debug.Assert(array != null); Debug.Assert(mapper != null); return(new PersistentArray <U>(array.Length, i => mapper(array[i]))); }
private PersistentGrid(int width, int height, IPersistentArray <IPersistentArray <T> > items) { Debug.Assert(width >= 0); Debug.Assert(height >= 0); Debug.Assert(items.Length == width); Debug.Assert(width == 0 || items.All(col => col.Length == height)); this._items = items; this.Width = width; this.Height = height; }
public PersistentGrid(int width, int height, Func <Vector2D, T> initializer) { Debug.Assert(width >= 0); Debug.Assert(height >= 0); Debug.Assert(initializer != null); this.Width = width; this.Height = height; this._items = new PersistentArray <IPersistentArray <T> >(width, x => { return(new PersistentArray <T>(height, y => initializer(new Vector2D(x, y)))); }); }
public static IPersistentArray <T> Update <T>(this IPersistentArray <T> array, int index, Func <T, T> updater) { return(array.Set(index, updater(array[index]))); }
public static bool IsValidIndex <T>(this IPersistentArray <T> array, int index) { return(0 <= index && index < array.Length); }