Question: Assuming I have the following markup:

```
<button id="dec">-</button>
<output id="out">0</output>
<button id="inc">+</button>
<button id="res">RESET</button>

```

And the following Rx.js script:

```
var total = 0

Rx.Observable.merge(
    // decrement
    Rx.Observable.fromEvent($('#dec'), 'click')
    .map(function() { return -1 }),

    // increment
    Rx.Observable.fromEvent($('#inc'), 'click')
    .map(function() { return +1 }),

    // reset
    Rx.Observable.fromEvent($('#res'), 'click')
    .map(function() { return -total })
) // merge
.forEach(function(delta) {
    total += delta
    $('#out').text(total)
})

```

Everything works as expected. Clicking the +/- increments/decrements the counter, and clicking 'RESET' resets it back to zero, but...I have the variable 'total' at the top. This is state, which if I subscribe to the values of functional reactive programming, is evil, no? If so, how do I remedy this? If I didn't have the reset button, I could just use `scan(seed, accumulator)`, but the functionality of the reset button is throwing me for a loop, as to how to do it 'stateless'.

[Working fiddle here](https://jsfiddle.net/jrop/8z34ggk1/3/).

Answer: 
Following @paulpdaniels answer, here is what i'm using with Ramda:

```
var hardSet  = Rx.Observable.fromEvent($('#set');
var decRes   = Rx.Observable.fromEvent($('#dec');
var incRes   = Rx.Observable.fromEvent($('#inc');

Rx.Observable.merge(
  incRes.map(function()  { return R.add(1); }),
  decRes.map(function()  { return R.add(-1); }),
  hardSet.map(function() { return R.always(0); })
).scan(function(prev, f) { 
  return f(prev); 
}, 0);

```
@Jrop I like this operator [`Rx.Observable.when`](http://xgrommx.github.io/rx-book/content/observable/observable_methods/when.html). With this one you can reproduce [`Bacon.update`](http://baconjs.github.io/api.html#bacon-update) very easy. This is my code and [jsbin](http://jsbin.com/gemore/2/edit?js,output) example:

```
const {when, fromEvent} = Rx.Observable;

const decObs = fromEvent(document.getElementById('dec'), 'click');
const incObs = fromEvent(document.getElementById('inc'), 'click');
const resetObs = fromEvent(document.getElementById('res'), 'click');

when(
    decObs.thenDo(_ => prev => prev - 1),
    incObs.thenDo(_ => prev => prev + 1),
    resetObs.thenDo(_ => prev => 0)
).startWith(0).scan((prev, f) => f(prev))
.subscribe(v => document.getElementById('out').innerHTML = v);

```

Also will be better if you look at this [`Join-calculus`](https://en.wikipedia.org/wiki/Join-calculus), [`New Release and Joins`](http://codebetter.com/matthewpodwysocki/2010/04/19/introduction-to-the-reactive-extensions-for-javascript-new-release-and-joins) and this [`Combining sequences`](http://introtorx.com/Content/v1.0.10621.0/12_CombiningSequences.html#AndThenWhen)