1

Using xstream, how can I create a stream that only emits when it's input stream emits a new value

Here is a diagram

input  -----1--1-1--2-3--3--3---5-|
output -----1-------2-3---------5-|
Ernest Okot
  • 880
  • 3
  • 8
  • 23

1 Answers1

1

While the core xstream library is comprised of a few well chosen operators, additional operators are included as extras and can accessed by their path.

import xs from 'xstream';
import dropRepeats from 'xstream/extra/dropRepeats'

const stream = xs.of(1, 1, 1, 2, 3, 3, 3, 5)
  .compose(dropRepeats())

stream.addListener({
   next: i => console.log(i),
   error: err => console.error(err),
   complete: () => console.log('completed')
});

The .compose operator is used to drop the extra methods into the stream.

source: https://github.com/staltz/xstream/blob/master/EXTRA_DOCS.md#dropRepeats

André Staltz
  • 13,304
  • 9
  • 48
  • 58
  • While this code may answer the question, providing additional context regarding _how_ and/or _why_ it solves the problem would improve the answer's long-term value. – Cameron Jan 27 '17 at 21:25
  • xstream creator here. Cameron, I believe the answer above was perfect. The "why" seems obvious or deducible once you read the name "dropRepeats" or the docs linked. – André Staltz Jan 28 '17 at 13:03