Skip to content

Commit

Permalink
fix(scan): match semantics of scan with reduce operator
Browse files Browse the repository at this point in the history
fixes #130
  • Loading branch information
tusharmath committed Feb 5, 2017
1 parent dcab42f commit 71ef235
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/operators/Reduce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {Scheduler} from '../types/Scheduler'
import {Curry} from '../lib/Curry'


export type TReducer<T, R> = {(previousValue: R, currentValue: T): R}
export type TReducer<T, R> = {(memory: R, current: T): R}
export type TSeed<R> = R
export type TSource<T> = Observable<T>
export type TResult<R> = Observable<R>
Expand Down
8 changes: 3 additions & 5 deletions src/operators/Scan.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
/**
* Created by tushar.mathur on 09/10/16.
*/


import {Observable} from '../types/core/Observable'
import {Observer} from '../types/core/Observer'
import {Scheduler} from '../types/Scheduler'
import {Subscription} from '../types/core/Subscription'
import {Curry} from '../lib/Curry'

export type TReducer <T, R> = (current: T, memory: R) => R
export type TReducer <T, R> = (memory: R, current: T) => R
export type TSeed <R> = R
export type TSource <T> = Observable<T>
export type TResult <R> = Observable<R>
Expand All @@ -22,7 +20,7 @@ class ScanObserver<T, V> implements Observer<T> {
}

next (val: T): void {
this.value = this.reducer(val, this.value)
this.value = this.reducer(this.value, val)
this.sink.next(this.value)
}

Expand Down Expand Up @@ -52,4 +50,4 @@ export const scan = Curry(function <T, V> (reducer: TReducer<T, V>, value: V, so
{<T, R>(reducer: TReducer<T, R>, seed: TSeed<R>, source: TSource<T>): TResult<R>} &
{<T, R>(reducer: TReducer<T, R>): {(seed: TSeed<R>, source: TSource<T>): TResult<R>}} &
{<T, R>(reducer: TReducer<T, R>, seed: TSeed<R>): {(source: TSource<T>): TResult<R>}} &
{<T, R>(reducer: TReducer<T, R>): { (seed: TSeed<R>): { (source: TSource<T>): TResult<R> } } }
{<T, R>(reducer: TReducer<T, R>): {(seed: TSeed<R>): {(source: TSource<T>): TResult<R>}}}
2 changes: 1 addition & 1 deletion test/test.Frames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import {scan} from '../src/operators/Scan'

test(t => {
const sh = TestScheduler.of(10)
const {results} = sh.start(() => scan((n, i) => i + 1, -1, frames()), 200, 250)
const {results} = sh.start(() => scan((i) => i + 1, -1, frames()), 200, 250)
t.is(toMarble(results), '-0123')
})
2 changes: 1 addition & 1 deletion test/test.IntervalObservable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {error} = ReactiveEvents

test('subscribe()', t => {
const sh = TestScheduler.of()
const {results} = sh.start(() => scan((i, j) => j + 1, -1, interval(10)), 200, 250)
const {results} = sh.start(() => scan(i => i + 1, -1, interval(10)), 200, 250)
t.is(toMarble(results), '-0123')
})

Expand Down

0 comments on commit 71ef235

Please sign in to comment.