Esempio n. 1
0
        /// <summary>
        /// Updates the element at <paramref name="index"/> using <paramref name="function"/>.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <param name="function">The function to apply to the element currently at <paramref name="index"/></param>
        /// <exception cref="ArgumentOutOfRangeException"><c>index</c> is out of range.</exception>
        /// <remarks>
        /// Equivalent to <code>SetAt(index, function(this[index])), but faster.</code>
        /// </remarks>
        public RandomAccessSequence <T> AdjustAt(int index, Func <T, T> function)
        {
            Requires.That.IsIndexInRange(this, index, "index").Check();
            var split        = _ft.SplitTreeAt(index, true, true);
            T   currentValue = split.Pivot.Value;

            return(new RandomAccessSequence <T>(
                       (split.Left | new Element(function(currentValue))) + split.Right));
        }