Ejemplo n.º 1
0
        /// <summary>
        /// Matches the left parser followed by the right parser, but only returns the left parser's matches.
        /// </summary>
        /// <typeparam name="TSource">The type of the source elements.</typeparam>
        /// <typeparam name="TIgnore">The type of the elements that are generated by the right parser.</typeparam>
        /// <typeparam name="TResult">The type of the elements that are generated by the left parser.</typeparam>
        /// <param name="parser">The parser from which to yield matches.</param>
        /// <param name="ignoreParser">The parser from which to ignore matches.</param>
        /// <returns>A parser that matches the left parser followed by the right parser, but only returns the
        /// left parser's matches.</returns>
        public static IObservableParser <TSource, TResult> IgnoreTrailing <TSource, TIgnore, TResult>(
            this IObservableParser <TSource, TResult> parser,
            IObservableParser <TSource, TIgnore> ignoreParser)
        {
            Contract.Requires(parser != null);
            Contract.Requires(ignoreParser != null);
            Contract.Ensures(Contract.Result <IObservableParser <TSource, TResult> >() != null);

            return(parser.SelectMany(_ => ignoreParser, (leading, _) => leading));
        }