Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Haskell-style monad do-notation for Ruby

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 Gemfile
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 do_notation.gemspec
README.md

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 (aanand.prasad@gmail.com)

Something went wrong with that request. Please try again.