带有结果选择器的扫描运算符
Scan operator with a result selector
在 Rx.NET 中,Aggregate
具有接受 resultSelector
的重载,但 Scan
不接受。是否有一个原因?我将如何创建一个接受结果选择器的 Scan
运算符,即带有签名:IObservable<TResult> Scan<TSource,TAccumulate,TResult>(this IObservable<TSource> source, TAccumulate seed, Func<TAccumulate,TSource,TAccumulate> accumulator, Func<TAccumulate,TResult> resultSelector)
.
下面的简单实现是否足够?
public static IObservable<TResult> Scan<TSource, TAccumulate, TResult>(
this IObservable<TSource> source,
TAccumulate seed,
Func<TAccumulate, TSource, TAccumulate> accumulator,
Func<TAccumulate, TResult> resultSelector)
{
return source.Scan(seed, accumulator).Select(resultSelector);
}
在 Rx.NET 中,Aggregate
具有接受 resultSelector
的重载,但 Scan
不接受。是否有一个原因?我将如何创建一个接受结果选择器的 Scan
运算符,即带有签名:IObservable<TResult> Scan<TSource,TAccumulate,TResult>(this IObservable<TSource> source, TAccumulate seed, Func<TAccumulate,TSource,TAccumulate> accumulator, Func<TAccumulate,TResult> resultSelector)
.
下面的简单实现是否足够?
public static IObservable<TResult> Scan<TSource, TAccumulate, TResult>(
this IObservable<TSource> source,
TAccumulate seed,
Func<TAccumulate, TSource, TAccumulate> accumulator,
Func<TAccumulate, TResult> resultSelector)
{
return source.Scan(seed, accumulator).Select(resultSelector);
}