Skip to content

Instantly share code, notes, and snippets.

@webhacking
Created January 24, 2019 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webhacking/6dbf509b2201ef91302bf1b0d5edf964 to your computer and use it in GitHub Desktop.
Save webhacking/6dbf509b2201ef91302bf1b0d5edf964 to your computer and use it in GitHub Desktop.
RxJS Example 05
import {from} from 'rxjs/internal/observable/from';
import {distinctUntilChanged} from 'rxjs/operators';
const source = [
{x: 1, y: 1},
{x: 1, y: 2},
{x: 3, y: 5},
{x: 6, y: 9},
{x: 2, y: 1},
{x: 3, y: 5},
{x: 8, y: 5},
{x: 2, y: 3},
{x: 1, y: 2},
{x: 9, y: 7},
];
const sequence$ = from(source);
const distance = 2.5;
sequence$
.pipe(
distinctUntilChanged((prev, next) => {
return Math.sqrt((prev.x - next.x)**2 + (prev.y - next.y)**2) < distance
})
)
.subscribe((val) => {
console.log(val)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment