예제 #1
0
        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])));
        }
예제 #2
0
        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])));
        }
예제 #3
0
        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;
        }
예제 #4
0
        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))));
            });
        }
예제 #5
0
 public static IPersistentArray <T> Update <T>(this IPersistentArray <T> array, int index, Func <T, T> updater)
 {
     return(array.Set(index, updater(array[index])));
 }
예제 #6
0
 public static bool IsValidIndex <T>(this IPersistentArray <T> array, int index)
 {
     return(0 <= index && index < array.Length);
 }