Skip to content

Instantly share code, notes, and snippets.

@hermanbanken
Last active July 1, 2016 15:41
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 hermanbanken/af547c0561d1f01cafe58931544b2ec9 to your computer and use it in GitHub Desktop.
Save hermanbanken/af547c0561d1f01cafe58931544b2ec9 to your computer and use it in GitHub Desktop.
Difficulties with implicit syntax #3
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/4.1.0/rx.all.min.js"></script>
var energyUse = new Rx.ReplaySubject(1);
var energyAccumulate = energyUse.scan((acc, value) => acc+value, 0);
energyAccumulate.subscribe(c => console.log(c));
energyUse.onNext(3);
// prints 3
energyUse.onNext(5);
// prints 8
energyUse.onNext(34);
// prints 42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment