Aanand Do Notation Save

Haskell-style monad do-notation for Ruby

Project README

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([], &:+)
  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

gem install do_notation

By Aanand Prasad ([email protected])

Open Source Agenda is not affiliated with "Aanand Do Notation" Project. README Source: aanand/do_notation
Stars
25
Open Issues
0
Last Commit
12 years ago
Repository

Open Source Agenda Badge

Open Source Agenda Rating