1

Probably it's simple question, but I can't resolve my problem. I have two streams and want mapping second stream by negative value of first stream.

jsfiddle - example

var price = change.map(1).scan(10, plus)
var money = buy.map(-price).merge(sale.map(price)).scan(100, plus);
doba
  • 25
  • 8
  • 1
    `price` is a property, not a value. Try `price.map(function(p){ return -p; })` – Bergi Feb 26 '15 at 11:49
  • 1
    is it just me or is this really over complicated ? :o – Pogrindis Feb 26 '15 at 11:52
  • It's not that complicated, with a bit of practice you get a feeling to separate the eventstreams / properties and the values. Using named functions and streams helps. – OlliM Feb 27 '15 at 16:00

1 Answers1

1

This answer is basically what bergi said in the comments.

var price = change.map(1).scan(10, plus)
var purchasePrice = price.map(function(p) { return -p }).sampledBy(buy)
var salePrice = price.sampledBy(sale)
var money = purchasePrice.merge(salePrice).scan(100, plus)

I used property.sampledBy(stream) instead of stream.map(property) - they do the same thing, but here I think it's clearer to use sampledBy.

OlliM
  • 7,023
  • 1
  • 36
  • 47