steveklabnik / frappuccino

Functional Reactive Programming in Ruby.
https://github.com/steveklabnik/frappuccino
MIT License
354 stars 33 forks source link

Add #sample to Property #19

Closed seadowg closed 11 years ago

seadowg commented 11 years ago

This adds a #sample method to Property that allows a Property to be sampled using an input Stream. This essentially allows for declarative polling of a Property. For instance, you could poll some text on a clock tick event and write it out:

message.sample(clock_tick).on_value do |value|
  puts message
end

One nice little note is that it actually allows a 'discrete' Stream to be converted to a 'continuous' Property and then back again:

Property.new(ini, stream).sample(stream) == stream

This is kind of silly but its also a nice example of the FRP world all coming together.

coveralls commented 11 years ago

Coverage Status

Coverage remained the same when pulling 244d543133eae0dbb8c1f9f46b2f54fb0e4fc889 on seadowg:prop_sample into f786b39ca12683b7c8ea61bd0474e84b2c10e572 on steveklabnik:master.

steveklabnik commented 11 years ago

This is an awesome solution, thanks so much!

seadowg commented 11 years ago

No problem :smile: