-
Notifications
You must be signed in to change notification settings - Fork 2
/
isEmpty.ts
36 lines (31 loc) · 843 Bytes
/
isEmpty.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { Operator, Observer, Unsubscribe } from '../index';
import { createSource } from '../sources';
import subscribe from '../utils/subscribe';
/**
* Emits false if the input observable emits any values, or emits true if the input observable completes without emitting any values
*
* @return callbag operator
*
* @public
*/
function isEmpty<I>(): Operator<I, boolean> {
return source => {
return createSource((next, complete, error) => {
let unsubscribe: Unsubscribe = () => {};
const observer: Observer<I> = {
next: () => {
next(false);
unsubscribe();
},
error,
complete: () => {
next(true);
complete();
},
};
unsubscribe = subscribe(source)(observer);
return unsubscribe;
});
};
}
export default isEmpty;