1 | import { Operator, Stream } from '../index';
|
2 | export declare class DropRepeatsOperator<T> implements Operator<T, T> {
|
3 | ins: Stream<T>;
|
4 | type: string;
|
5 | out: Stream<T>;
|
6 | isEq: (x: T, y: T) => boolean;
|
7 | private v;
|
8 | constructor(ins: Stream<T>, fn: ((x: T, y: T) => boolean) | undefined);
|
9 | _start(out: Stream<T>): void;
|
10 | _stop(): void;
|
11 | _n(t: T): void;
|
12 | _e(err: any): void;
|
13 | _c(): void;
|
14 | }
|
15 | /**
|
16 | * Drops consecutive duplicate values in a stream.
|
17 | *
|
18 | * Marble diagram:
|
19 | *
|
20 | * ```text
|
21 | * --1--2--1--1--1--2--3--4--3--3|
|
22 | * dropRepeats
|
23 | * --1--2--1--------2--3--4--3---|
|
24 | * ```
|
25 | *
|
26 | * Example:
|
27 | *
|
28 | * ```js
|
29 | * import dropRepeats from 'xstream/extra/dropRepeats'
|
30 | *
|
31 | * const stream = xs.of(1, 2, 1, 1, 1, 2, 3, 4, 3, 3)
|
32 | * .compose(dropRepeats())
|
33 | *
|
34 | * stream.addListener({
|
35 | * next: i => console.log(i),
|
36 | * error: err => console.error(err),
|
37 | * complete: () => console.log('completed')
|
38 | * })
|
39 | * ```
|
40 | *
|
41 | * ```text
|
42 | * > 1
|
43 | * > 2
|
44 | * > 1
|
45 | * > 2
|
46 | * > 3
|
47 | * > 4
|
48 | * > 3
|
49 | * > completed
|
50 | * ```
|
51 | *
|
52 | * Example with a custom isEqual function:
|
53 | *
|
54 | * ```js
|
55 | * import dropRepeats from 'xstream/extra/dropRepeats'
|
56 | *
|
57 | * const stream = xs.of('a', 'b', 'a', 'A', 'B', 'b')
|
58 | * .compose(dropRepeats((x, y) => x.toLowerCase() === y.toLowerCase()))
|
59 | *
|
60 | * stream.addListener({
|
61 | * next: i => console.log(i),
|
62 | * error: err => console.error(err),
|
63 | * complete: () => console.log('completed')
|
64 | * })
|
65 | * ```
|
66 | *
|
67 | * ```text
|
68 | * > a
|
69 | * > b
|
70 | * > a
|
71 | * > B
|
72 | * > completed
|
73 | * ```
|
74 | *
|
75 | * @param {Function} isEqual An optional function of type
|
76 | * `(x: T, y: T) => boolean` that takes an event from the input stream and
|
77 | * checks if it is equal to previous event, by returning a boolean.
|
78 | * @return {Stream}
|
79 | */
|
80 | export default function dropRepeats<T>(isEqual?: ((x: T, y: T) => boolean) | undefined): (ins: Stream<T>) => Stream<T>;
|