steveklabnik/frappuccino
Functional Reactive Programming in Ruby.
{ "createdAt": "2013-04-22T14:53:51Z", "defaultBranch": "master", "description": "Functional Reactive Programming in Ruby.", "fullName": "steveklabnik/frappuccino", "homepage": "https://github.com/steveklabnik/frappuccino", "language": "Ruby", "name": "frappuccino", "pushedAt": "2016-02-09T21:52:19Z", "stargazersCount": 354, "topics": [], "updatedAt": "2025-08-26T03:22:18Z", "url": "https://github.com/steveklabnik/frappuccino"}Frappuccino
Section titled “Frappuccino”Functional Reactive Programming for Ruby.
Installation
Section titled “Installation”Add this line to your application’s Gemfile:
gem 'frappuccino'And then execute:
$ bundleOr install it yourself as:
$ git clone https://github.com/steveklabnik/frappuccino$ cd frappuccino$ bundle$ rake installBasically, this:
require 'frappuccino'
class Button def push emit(:pushed) # emit sends a value into the stream endend
button = Button.newstream = Frappuccino::Stream.new(button)
counter = stream .map {|event| event == :pushed ? 1 : 0 } # convert events to ints .inject(0) {|sum, n| sum + n } # add them up
counter.now # => 0
button.pushbutton.pushbutton.push
counter.now # => 3
button.push
counter.now # => 4You can also map via a hash, if you prefer:
.map(:pushed => 1, :default => 0)You can also register callbacks to a Stream. These will be executed for each event that occurs in the Stream:
stream.on_value do |event| puts "I got a #{event}!"endYou can combine two streams together:
merged_stream = stream_one.merge(stream_two)
# or
merged_stream = Frappuccino::Stream.merge(one_stream , other_stream)
# or
merged_stream = Frappuccino::Stream.new(button_one, button_two)You can select events from a stream, too:
stream = Frappuccino::Stream.new(button, something_else)filtered_stream = stream.select{|event| event == :pushed }
filtered_stream.on_value do |event| # event will only ever be :pushedendContributing
Section titled “Contributing”- Fork it
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create new Pull Request


