Exemple #1
0
        /// <summary>
        /// Appends the results of each result sequence from the specified <paramref name="parser"/> into an <see cref="IList{TResult}"/>.
        /// </summary>
        /// <typeparam name="TSource">The type of the source elements.</typeparam>
        /// <typeparam name="TResult">The type of the elements that are generated by the parser.</typeparam>
        /// <param name="parser">The parser that produces a sequence of result sequences to be aggregated.</param>
        /// <returns>A parser that returns the results aggregated into an <see cref="IList{TResult}"/>.</returns>
        public static IObservableParser <TSource, IList <TResult> > ToList <TSource, TResult>(
            this IObservableParser <TSource, IObservable <TResult> > parser)
        {
            Contract.Requires(parser != null);
            Contract.Ensures(Contract.Result <IObservableParser <TSource, IList <TResult> > >() != null);

            return(parser.Aggregate(
                       () => new List <TResult>(),
                       (list, result) =>
            {
                list.Add(result);
                return list;
            },
                       list => (IList <TResult>)list.AsReadOnly()));
        }