Exemplo n.º 1
0
        public bool Update(int index, Func <T, T> itemUpdateFactory, Predicate <T> check, out bool isEmpty)
        {
            if (itemUpdateFactory == null)
            {
                throw new ArgumentNullException(nameof(check));
            }
            if (check == null)
            {
                throw new ArgumentNullException(nameof(check));
            }
            TNeedle newNeedle = null;

            if (_entries.Update(index, ReplacementFactory, ReplacementCheck, out isEmpty))
            {
                return(true);
            }
            if (newNeedle != null)
            {
                Reservoir.DonateNeedle(newNeedle);
            }
            return(false);

            TNeedle ReplacementFactory(TNeedle needle) => newNeedle = Reservoir.GetNeedle(itemUpdateFactory(needle.Value));
            bool ReplacementCheck(TNeedle needle) => check(needle.Value);
        }
Exemplo n.º 2
0
 public bool Update(int index, Func<T, T> itemUpdateFactory, Predicate<T> check, out bool isEmpty)
 {
     TNeedle newNeedle = null;
     Func<TNeedle, TNeedle> replacementFactory = needle => newNeedle = NeedleReservoir<T, TNeedle>.GetNeedle(itemUpdateFactory(needle.Value));
     Predicate<TNeedle> replacementCheck = needle => check(needle.Value);
     if (_entries.Update(index, replacementFactory, replacementCheck, out isEmpty))
     {
         return true;
     }
     if (newNeedle != null)
     {
     }
     NeedleReservoir<T, TNeedle>.DonateNeedle(newNeedle);
     return false;
 }