Skip to content

Commit

Permalink
perf(reduce): add fast-path for reducing over scalar observables
Browse files Browse the repository at this point in the history
  • Loading branch information
benlesh committed Oct 14, 2015
1 parent eb11736 commit 4c65136
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/observables/ScalarObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,16 @@ export default class ScalarObservable<T> extends Observable<T> {
return new EmptyObservable();
}
}

reduce<R>(project: (acc: R, x: T) => R, acc?: R): Observable<R> {
if (typeof acc === 'undefined') {
return <any>this;
}
let result = tryCatch(project)(acc, this.value);
if (result === errorObject) {
return new ErrorObservable(errorObject.e);
} else {
return new ScalarObservable(result);
}
}
}

0 comments on commit 4c65136

Please sign in to comment.