Ejemplo n.º 1
0
 /// <summary>
 ///     Applies the specified function on every item in the collection, from last to first, and stops when the function returns false.
 /// </summary>
 /// <param name="function"> The function. </param>
 /// <returns> </returns>
 /// <exception cref="ArgumentNullException">Thrown if the argument null.</exception>
 public virtual bool ForEachWhile(Func <TElem, bool> function)
 {
     if (function == null)
     {
         throw Errors.Argument_null("function");
     }
     foreach (var item in this)
     {
         if (!function(item))
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 2
0
 /// <summary>
 ///   Filters the collection using the specified predicate.
 /// </summary>
 /// <param name="predicate"> The predicate. </param>
 /// <returns> </returns>
 /// <exception cref="ArgumentNullException">Thrown if the argument is null.</exception>
 public virtual TIterable Where(Func <TElem, bool> predicate)
 {
     if (predicate == null)
     {
         throw Errors.Argument_null("predicate");
     }
     using (var builder = EmptyBuilder) {
         ForEach(v => {
             if (predicate(v))
             {
                 builder.Add(v);
             }
         });
         return(builder.Produce());
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 ///   Implementation for a method that incrementally applies an accumulator over the collection, and returns a sequence of partial results. Runs from last to first.
 /// </summary>
 /// <typeparam name="TElem2"> The type of the element in the return collection. </typeparam>
 /// <typeparam name="TRSeq"> The type of the return provider. </typeparam>
 /// <param name="bFactory"> A prototype instance of the resulting collection provider, used as a builder factory. </param>
 /// <param name="initial"> The initial value for the accumulator. </param>
 /// <param name="accumulator"> The accumulator. </param>
 /// <exception cref="ArgumentNullException">Thrown if the argument null.</exception>
 /// <returns> </returns>
 protected virtual TRSeq _ScanBack <TElem2, TRSeq>(TRSeq bFactory, TElem2 initial, Func <TElem2, TElem, TElem2> accumulator)
     where TRSeq : IBuilderFactory <ISequentialBuilder <TElem2, TRSeq> >
 {
     bFactory.CheckNotNull("bFactory");
     if (accumulator == null)
     {
         throw Errors.Argument_null("accumulator");
     }
     using (var builder = bFactory.EmptyBuilder)
     {
         AggregateBack(initial, (r, v) =>
         {
             r = accumulator(r, v);
             builder.Add(r);
             return(r);
         });
         return(builder.Produce());
     }
 }