Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to push based implementation #5

Merged
merged 4 commits into from Apr 23, 2013

Conversation

seadowg
Copy link
Contributor

@seadowg seadowg commented Apr 23, 2013

Howdy,

This switches the MVP code to use a very basic push based implementation rather than an array one. Array implementations of FRP events allow for arbitrary access to the past but require large quantities of memory and generally don't match up to the requirements of an infinite stream. The push based approach however gives you a pretty nice way of sticking to the semantics (as long as people follow the rules) without storing the whole past.

One caveat of using a push based implementation is that the following would happen:

stream = Frappuccino::Stream.new(button)
button.push
counter = stream.map {|event| event == :pushed ? 1 : 0 }.inject(0) {|sum, n| sum + n }
counter.to_i # => 0

This means that you have to declare the event processing you want upfront if you care about the whole stream.

I've also switched the Map class to extend Stream (which I'm guessing would have been the idea eventually anyway).

</:neckbeard:>


module Frappuccino
class Stream
attr_reader :values

include Observable
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Streams to dispatch values as well as Source

@steveklabnik
Copy link
Owner

This is super awesome, thank you so much! The arrays were very MVP, you're totally right about memory etc.

This means that you have to declare the event processing you want upfront if you care about the whole stream.

I'm slightly confused, it seems your example moves the source event before the processing, not after.

@seadowg
Copy link
Contributor Author

seadowg commented Apr 23, 2013

Sorry that's badly worded. I mean you need to declare all the relationships before the events actually 'occur'. Ie in my example we create a new stream after the button is pressed so we are out of date: Conceptually the value of the inject should be 1.

@steveklabnik
Copy link
Owner

Oh, oh oh. Yes, it's zero, that's the part that I'm missing.

I'm okay with this.

steveklabnik added a commit that referenced this pull request Apr 23, 2013
Switch to push based implementation
@steveklabnik steveklabnik merged commit 651cf1b into steveklabnik:master Apr 23, 2013
@steveklabnik
Copy link
Owner

Thanks so much again for this! :)

@seadowg
Copy link
Contributor Author

seadowg commented Apr 23, 2013

No problem 😄. I loves me some FRP.

@steveklabnik
Copy link
Owner

Awesome 🤘

I haven't built anything with it yet, just read things for a long time, so this project is my way of tackling it. Any good literature I should be reading?

@seadowg
Copy link
Contributor Author

seadowg commented Apr 23, 2013

The original '97 paper (http://conal.net/papers/icfp97/) and the later revisit by Conal Elliott are pretty awesome (http://conal.net/papers/push-pull-frp/) but also take a bit of work to understand (something I still don't think I've fully achieved). If you haven't read them though they provide a proper overview of the semantics which a lot of implementations cherry pick from.

This Stack Overflow question is also provides some insights:
http://stackoverflow.com/questions/1028250/what-is-functional-reactive-programming.

I've implemented a couple of FRP projects also, only one of them really being 'pure', which might be interesting (on top of others like bacon.js which I'm guessing you've seen):

@steveklabnik
Copy link
Owner

Yeah, I wrote this gem because I'm at RealtimeConf EU and we were discussing FRP and bacon.js. Thanks for the links, I'll check all those out. I have enough functional background that I should be able to make my way through the literature...

@seadowg
Copy link
Contributor Author

seadowg commented Apr 23, 2013

Ah awesome. Enjoy!

On Tue, Apr 23, 2013 at 12:35 AM, Steve Klabnik notifications@github.com
wrote:

Yeah, I wrote this gem because I'm at RealtimeConf EU and we were discussing FRP and bacon.js. Thanks for the links, I'll check all those out. I have enough functional background that I should be able to make my way through the literature...

Reply to this email directly or view it on GitHub:
#5 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants