Ejemplo n.º 1
0
        /// <summary>
        /// Updates values of all keys. For each key in the dictionary, if
        /// <code>updateFunc(key, this[key])</code> returns <code>None</code>, the
        /// key is removed; if it returns <code>Some(newValue)</code>, the
        /// current value is replaced with <c>newValue</c>.
        /// </summary>
        /// <param name="updateFunc">The updating function.</param>
        /// <returns>The resulting dictionary.</returns>
        public TreeDictionary <TKey, TValue, TComparer> MapPartial(Func <TKey, TValue, Optional <TValue> > updateFunc)
        {
            if (Count == 0)
            {
                return(this);
            }
            var newValue = updateFunc(_key, _value);

            return(newValue.HasValue
                       ? Unbalanced(newValue.Value, _left.MapPartial(updateFunc), _right.MapPartial(updateFunc))
                       : GlueUnbalanced(_left.MapPartial(updateFunc), _right.MapPartial(updateFunc)));
        }