Skip to content

Commit

Permalink
fix(dropRepeats): move dropRepeats from core to extra
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Medeiros committed Apr 8, 2016
1 parent c481cc8 commit 78851c8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
5 changes: 0 additions & 5 deletions src/Stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {MapToOperator} from './operator/MapToOperator';
import {FilterOperator} from './operator/FilterOperator';
import {TakeOperator} from './operator/TakeOperator';
import {DropOperator} from './operator/DropOperator';
import {DropRepeatsOperator} from './operator/DropRepeatsOperator';
import {DebugOperator} from './operator/DebugOperator';
import {FoldOperator} from './operator/FoldOperator';
import {LastOperator} from './operator/LastOperator';
Expand Down Expand Up @@ -192,10 +191,6 @@ export class Stream<T> implements InternalListener<T> {
return new Stream<T>(new DropOperator(amount, this));
}

dropRepeats(isEqual: (x: T, y: T) => boolean = null): Stream<T> {
return new Stream<T>(new DropRepeatsOperator(isEqual, this));
}

last(): Stream<T> {
return new Stream<T>(new LastOperator(this));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ export class DropRepeatsOperator<T> implements Operator<T, T> {
this.ins._remove(this.proxy);
}
}

export default function dropRepeats<T>(isEqual: (x: T, y: T) => boolean = null): (ins: Stream<T>) => Stream<T> {
return function dropRepeatsOperator(ins: Stream<T>): Stream<T> {
return new Stream<T>(new DropRepeatsOperator(isEqual, ins));
};
}
9 changes: 5 additions & 4 deletions tests/operator/dropRepeats.ts → tests/extra/dropRepeats.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import xs from '../../src/index';
import xs, {Stream} from '../../src/index';
import dropRepeats from '../../src/extra/dropRepeats';
import * as assert from 'assert';

describe('Stream.prototype.dropRepeats', () => {
describe('dropRepeats (extra)', () => {
it('should drop consecutive duplicate numbers (as events)', (done) => {
const stream = xs.of(1, 2, 1, 1, 1, 2, 3, 4, 3, 3).dropRepeats();
const stream = xs.of(1, 2, 1, 1, 1, 2, 3, 4, 3, 3).compose(dropRepeats());
const expected = [1, 2, 1, 2, 3, 4, 3];

stream.addListener({
Expand All @@ -20,7 +21,7 @@ describe('Stream.prototype.dropRepeats', () => {

it('should drop consecutive \'duplicate\' strings, with a custom isEqual', (done) => {
const stream = xs.of('a', 'b', 'a', 'A', 'B', 'b')
.dropRepeats((x, y) => x.toLowerCase() === y.toLowerCase());
.compose(dropRepeats((x: string, y: string) => x.toLowerCase() === y.toLowerCase()));
const expected = ['a', 'b', 'a', 'B'];

stream.addListener({
Expand Down
1 change: 0 additions & 1 deletion tests/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ describe('Stream', () => {
assert.equal(typeof stream.filter, 'function');
assert.equal(typeof stream.take, 'function');
assert.equal(typeof stream.drop, 'function');
assert.equal(typeof stream.dropRepeats, 'function');
assert.equal(typeof stream.last, 'function');
assert.equal(typeof stream.startWith, 'function');
assert.equal(typeof stream.endWhen, 'function');
Expand Down

0 comments on commit 78851c8

Please sign in to comment.