@@ -6,9 +6,9 @@ import { OperatorFunction, MonoTypeOperatorFunction } from '../types';
6
6
import { pipe } from '../util/pipe' ;
7
7
8
8
/* tslint:disable:max-line-length */
9
+ export function reduce < T , R > ( accumulator : ( acc : R , value : T , index : number ) => R , seed : R ) : OperatorFunction < T , R > ;
9
10
export function reduce < T > ( accumulator : ( acc : T , value : T , index : number ) => T , seed ?: T ) : MonoTypeOperatorFunction < T > ;
10
- export function reduce < T > ( accumulator : ( acc : T [ ] , value : T , index : number ) => T [ ] , seed : T [ ] ) : OperatorFunction < T , T [ ] > ;
11
- export function reduce < T , R > ( accumulator : ( acc : R , value : T , index : number ) => R , seed ?: R ) : OperatorFunction < T , R > ;
11
+ export function reduce < T , R > ( accumulator : ( acc : R , value : T , index : number ) => R ) : OperatorFunction < T , R > ;
12
12
/* tslint:enable:max-line-length */
13
13
14
14
/**
@@ -62,20 +62,20 @@ export function reduce<T, R>(accumulator: (acc: R, value: T, index: number) => R
62
62
* @method reduce
63
63
* @owner Observable
64
64
*/
65
- export function reduce < T , R > ( accumulator : ( acc : R , value : T , index ?: number ) => R , seed ?: R ) : OperatorFunction < T , R > {
65
+ export function reduce < T , R > ( accumulator : ( acc : T | R , value : T , index ?: number ) => T | R , seed ?: T | R ) : OperatorFunction < T , T | R > {
66
66
// providing a seed of `undefined` *should* be valid and trigger
67
67
// hasSeed! so don't use `seed !== undefined` checks!
68
68
// For this reason, we have to check it here at the original call site
69
69
// otherwise inside Operator/Subscriber we won't know if `undefined`
70
70
// means they didn't provide anything or if they literally provided `undefined`
71
71
if ( arguments . length >= 2 ) {
72
- return function reduceOperatorFunctionWithSeed ( source : Observable < T > ) : Observable < R > {
72
+ return function reduceOperatorFunctionWithSeed ( source : Observable < T > ) : Observable < T | R > {
73
73
return pipe ( scan ( accumulator , seed ) , takeLast ( 1 ) , defaultIfEmpty ( seed ) ) ( source ) ;
74
74
} ;
75
75
}
76
- return function reduceOperatorFunction ( source : Observable < T > ) : Observable < R > {
76
+ return function reduceOperatorFunction ( source : Observable < T > ) : Observable < T | R > {
77
77
return pipe (
78
- scan ( ( acc : R , value : T , index : number ) : R => accumulator ( acc , value , index + 1 ) ) ,
78
+ scan < T , T | R > ( ( acc , value , index ) => accumulator ( acc , value , index + 1 ) ) ,
79
79
takeLast ( 1 ) ,
80
80
) ( source ) ;
81
81
} ;
0 commit comments