baconjs / bacon.js

Functional reactive programming library for TypeScript and JavaScript
https://baconjs.github.io
MIT License
6.47k stars 330 forks source link

Change Property.delay behavior #334

Closed raimohanska closed 10 years ago

raimohanska commented 10 years ago

I propose we change Property.delay to also delay the init value. It's a bit confusing that the delay method only delays changes. Any objections?

phadej commented 10 years ago

It depends how you understand what Property is.

I understand Property as continuos function of time var f = f(t) = …. So delayed property is g = f.delay(d) = g(t) = f(t - d), and the initial value of Property is value at negative infinity until first value change f(-∞) = initial than obviously initial value should (can not) be delayed.

The property without initial value of type Property[T] could be understood as property with initial value of None of type Property[Option[T]], without boilerplate to mangle Option value.

Similarly EventStream is a collection (set) of discrete event timestamps (without even any values assigned to them). Eg. mouse clicks is just set of time values, the mouse position or clicked element could be understood as related Property which is sampled by the clicks stream. However because of engineering reasons the reality is opposite.

philipnilsson commented 10 years ago

I agree, I think the current behaviour vibes better with the semantics of properties. I'd expect stream.delay(x).toProperty(y) = stream.toProperty(y).delay(x)

On Fri, Feb 14, 2014 at 3:27 PM, Oleg Grenrus notifications@github.comwrote:

It depends how you understand what Property is.

I understand Property as continuos function of time var f = f(t) = …. So delayed property is g = f.delay(d) = g(t) = f(t - d), and the initial value of Property is value at negative infinity until first value change f(-∞) = initial than obviously initial value should (can not) be delayed.

The property without initial value of type Property[T] could be understood as property with initial value of None of type Property[Option[T]], without boilerplate to mangle Option value.

Similarly EventStream is a collection (set) of discrete event timestamps (without even any values assigned to them). Eg. mouse clicks is just set of time values, the mouse position or clicked element could be understood as related Property which is sampled by the clicks stream. However because of engineering reasons the reality is opposite.

— Reply to this email directly or view it on GitHubhttps://github.com/baconjs/bacon.js/issues/334#issuecomment-35087523 .

Philip Nilsson, +46 2922 4651