Star

Created With

linkBoolean Operations

Boolean operations allow you to conduct boolean arithmetics on observables emitting boolean values.


linkEquality Checks

You can use eq() to check equality of multiple observables / boolean values:

1import { eq } from 'rxmetics';

2import { mod } from 'rxmetics/pipes';

3import { interval } from 'rxjs';

4

5

6eq(

7 interval(1000).pipe(mod(2)),

8 interval(500).pipe(mod(2))

9).subscribe(console.log);

10

11// Result:

12// > true

13// > false

14// > true

15// > false

play_arrow

You can also use eq() pipe instead:

1import { mod, eq } from 'rxmetics/pipes';

2import { interval } from 'rxjs';

3

4

5interval(1000).pipe(

6 mod(2),

7 eq(interval(500).pipe(mod(2)))

8)

9.subscribe(console.log);

You can also use neq() or neq() pipe for non-equality checks.

error IMPORTANT

eq() and neq() conduct strict equality check, i.e. they use === and !== operators respectively.


linknot()

Negates incoming boolean values:

1import { not, eq, neq } from 'rxmetics';

2import { interval } from 'rxjs';

3

4const i1 = interval(1000);

5const i2 = interval(1100);

6

7eq(

8 not(eq(i1, i2)),

9 neq(i1, i2)

10).subscribe(v => document.body.textContent = v);

play_arrow

You can use it as a pipe as well:

1import { not, eq, neq } from 'rxmetics'; // --> alternatively you can import `not` from 'rxmetics/pipes';

2import { interval } from 'rxjs';

3

4const i1 = interval(1000);

5const i2 = interval(1100);

6

7eq(

8 eq(i1, i2).pipe(not),

9 neq(i1, i2)

10).subscribe(v => document.body.textContent = v);


linkand()

Will AND two (or more) booleans or observables:

1import { and } from 'rxmetics';

2import { fromEvent } from 'rxjs';

3import { pluck, map } from 'rxjs/operators';

4

5

6and(

7 fromEvent(document, 'mousemove')

8 .pipe(pluck('clientX'), map(x => x > window.innerWidth / 2)),

9 fromEvent(document, 'mousemove')

10 .pipe(pluck('clientY'), map(x => x > window.innerHeight / 2))

11)

12.subscribe(v => {

13 if (v) document.body.classList.add('active');

14 else document.body.classList.remove('active');

15});

play_arrow

You can also use the and() pipe instead:

1import { and } from 'rxmetics/pipes';

2import { fromEvent } from 'rxjs';

3import { pluck, map } from 'rxjs/operators';

4

5fromEvent(document, 'mousemove')

6.pipe(

7 pluck('clientX'), map(x => x > window.innerWidth / 2),

8 and(fromEvent(document, 'mousemove')

9 .pipe(pluck('clientY'), map(x => x > window.innerHeight / 2))

10 )

11)

12.subscribe(v => {

13 if (v) document.body.classList.add('active');

14 else document.body.classList.remove('active');

15});


linkor()

Will AND two (or more) booleans or observables:

1import { or } from 'rxmetics';

2import { fromEvent } from 'rxjs';

3import { pluck, map } from 'rxjs/operators';

4

5

6or(

7 fromEvent(document, 'mousemove')

8 .pipe(pluck('clientX'), map(x => x > window.innerWidth / 2)),

9 fromEvent(document, 'mousemove')

10 .pipe(pluck('clientY'), map(x => x > window.innerHeight / 2))

11)

12.subscribe(v => {

13 if (v) document.body.classList.add('active');

14 else document.body.classList.remove('active');

15});

play_arrow

You can also use the and() pipe instead:

1import { or } from 'rxmetics/pipes';

2import { fromEvent } from 'rxjs';

3import { pluck, map } from 'rxjs/operators';

4

5fromEvent(document, 'mousemove')

6.pipe(

7 pluck('clientX'), map(x => x > window.innerWidth / 2),

8 or(fromEvent(document, 'mousemove')

9 .pipe(pluck('clientY'), map(x => x > window.innerHeight / 2))

10 )

11)

12.subscribe(v => {

13 if (v) document.body.classList.add('active');

14 else document.body.classList.remove('active');

15});


linktruthy()

Checks if emitted values are truthy. It basically applies the !! operator. Like not(), it can be used as a function or as a pipe:

1import { truthy, eq } from 'rxmetics';

2

3const a$ = ...

4

5truthy(a$) // --> these two are the same

6a$.pipe(truthy) // --> these two are the same


Boolean OperationsEquality Checksnot()and()or()truthy()

Home Numeric Operations String Operations Boolean Operations Generic Functions