/// <summary> /// Appends only a message when the predicate function returns true. /// For recursion: Recursion will only occur when the predicate returns true. /// If no predicate is specified, a default predicate that returns true unless the selector returns default(TMessageType) is used /// </summary> /// <typeparam name="TMessageType">The message type /// </typeparam> /// <param name="builder">The append decorator builder</param> /// <param name="predicate">The predicate</param> /// <returns>A builder</returns> public static IAppendManyDecoratorBuilder <TMessageType> Where <TMessageType>(this IAppendManyDecoratorBuilder <TMessageType> builder, Func <TMessageType, bool> predicate) { if (predicate == null) { throw new ArgumentNullException(nameof(predicate)); } return(builder.Where((message, token) => Task.FromResult(predicate(message)))); }
/// <summary> /// The function used to select the message to append /// </summary> /// <typeparam name="TMessageType">The message type /// </typeparam> /// <param name="builder"> /// The append decorator builder /// </param> /// <param name="messageSelector"> /// The function used to select the message to append /// </param> /// <returns> /// A builder /// </returns> public static IAppendManyDecoratorBuilder <TMessageType> Select <TMessageType>(this IAppendManyDecoratorBuilder <TMessageType> builder, Func <TMessageType, IEnumerable <TMessageType> > messageSelector) { if (messageSelector == null) { throw new ArgumentNullException(nameof(messageSelector)); } return(builder.Select((message, token) => Task.FromResult(messageSelector(message)))); }