public
Rubygem
Description: Haskell-style monad do-notation for Ruby
Homepage:
Clone URL: git://github.com/aanand/ruby-do-notation.git
aanand (author)
Mon Jun 23 09:21:15 -0700 2008
commit  271935b427d99af792cf2a5cca3ada8f40a2bc34
tree    d8534e1ed6ea0025d6e095d12bdedb712f5990d7
parent  c18770f96d126215cda55328186509695f2cbbda
name age message
file .gitignore Loading commit data...
file Manifest Mon Jun 23 03:28:28 -0700 2008 Okay, README is rdoc syntax now [aanand]
file README.rdoc Mon Jun 23 09:06:23 -0700 2008 gah, that shouldn't be there [Aanand Prasad]
file Rakefile
directory lib/
file ruby-do-notation.gemspec
directory test/

Haskell-style monad do-notation for Ruby

Example:

    require 'do_notation'

    class Array
      include Monad

      def self.unit x
        [x]
      end

      def bind &f
        map(&f).inject([]){ |a,b| a+b }
      end
    end

    Array.run do
      x <- ["first", "second"]
      y <- ["once", "twice"]

      unit("#{x} cousin #{y} removed")
    end

The above code returns the array:

    ["first cousin once removed",
     "first cousin twice removed",
     "second cousin once removed",
     "second cousin twice removed"]

For more examples, see the test suite.

Installation

There’s a gem hosted on Github, so follow the setup instructions at gems.github.com and then run:

    sudo gem install aanand-ruby-do-notation

By Aanand Prasad (aanand.prasad@gmail.com)