Now uses arrows!!
[ruby-do-notation.git] / README
blobf6ea8a99ea1c275b4fb5a5c35ed8ee3c76dfc63e
1 Haskell-style monad do-notation for Ruby
3 Example:
5     class Array
6       extend Monad
7       
8       def self.unit x
9         [x]
10       end
11       
12       def bind &f
13         map(&f).inject([]){ |a,b| a+b }
14       end
15     end
16     
17     Array.run do
18       x <- ['A', 'a']
19       y <- ['B', 'b']
20       
21       unit(x+y)
22     end
23     
24     # => ["AB", "Ab", "aB", "ab"]
26 Its biggest failing, and I don't see a way
27 out, is that you don't get lexical scope. ParseTree
28 is wonderful, but it can't work miracles.
30 You can work around it, though, by passing in
31 stuff from the outside as arguments to `run',
32 and specifying those arguments on the block
33 you pass in as well.
35 For more examples, see the test suite.
37 By Aanand Prasad (aanand.prasad@gmail.com)