Check

A check() is like a filter(), except that it has two outputs, one for passing values and one for failing values:
/*!*/import { wrap, check, sink } from '@connectv/core';
import { interval } from 'rxjs';

let even = document.getElementById('even');
let odd = document.getElementById('odd');


wrap(interval(1000))
/*!*/.to(check(x => x % 2 == 0))  //--> separate by being even or odd
/*!*/.serialTo(
/*!*/  sink(v => even.innerHTML += ' ' + v),
/*!*/  sink(v => odd.innerHTML += ' ' + v)
).subscribe();
If you need to connect to a check() explicitly instead of implicitly, you can do it like this:
let c = check(x => x % 2 == 0);

wrap(interval(1000)).to(c.input);
c.pass.subscribe(v => even.innerHTML += ' ' + v);
c.fail.subscribe(v => even.innerHTML += ' ' + v);


Similar to filter(), you can pass asynchronous predicates to check():
/*!*/import { wrap, check, sink } from '@connectv/core';
import { interval } from 'rxjs';

let timer = document.getElementById('timer');
let even = document.getElementById('even');
let odd = document.getElementById('odd');


wrap(interval(500))
.to(sink(v => timer.innerHTML = v))          //--> display timer for reference
/*!*/.to(check((x, done) =>                       //--> return results with a delay
/*!*/  setTimeout(() => done(x % 2 == 0), 2000)))
.serialTo(
  sink(v => even.innerHTML += ' ' + v),
  sink(v => odd.innerHTML += ' ' + v)
).subscribe();

Signature

Every check() has one "value" input, one "pass" output and one "fail" output:
let c = check(x => x % 2 == 0);

x.in('value') == x.input;
x.out('pass') == x.pass;
x.out('fail') == x.fail;


Further reading




Copied to Clipboard!