Skip to content

Commit b9a3614

Browse files
committed
Update README. :doc:
1 parent 6bd1526 commit b9a3614

1 file changed

Lines changed: 28 additions & 15 deletions

File tree

README.md

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,39 @@
77

88
## Synopsis
99

10-
By definition a *Functor* is simply a first class method, but these are common
11-
in Ruby in the form of Method and Proc classes. So for Ruby a Functor is a more
12-
specialized Higher Order Function. Essentally, a Functor can vary its behavior
13-
accorrding to the operation applied to it.
10+
By definition a *Functor* is simply a first class method, but these are quite
11+
common in Ruby with the `Method`, `UnboundMethod` and `Proc` classes. So for
12+
Ruby we define a Functor as a *Higher Order Function*. Essentially, a functor
13+
can vary its behavior according to the operation applied to it. Consider the
14+
following simplistic example.
1415

1516
f = Functor.new { |op, x| x.send(op, x) }
1617

17-
(f + 1) #=> 2
18-
(f + 2) #=> 4
19-
(f + 3) #=> 6
20-
(f * 1) #=> 1
21-
(f * 2) #=> 4
22-
(f * 3) #=> 9
18+
f + 1 #=> 2
19+
f + 2 #=> 4
20+
f + 3 #=> 6
21+
f * 1 #=> 1
22+
f * 2 #=> 4
23+
f * 3 #=> 9
2324

24-
You can also think of the Functor as an *anonymous generic delegator*. Instead
25-
of having to create a specialized delegator class, we can use a Functor. Functors
26-
are perfect when the delegation require is minimal.
25+
Notice that the constructor takes a block, the first argument of which is always
26+
the method operating on the functor. All subsequent arguments are optional
27+
dependent upon the use case.
2728

28-
NOTE: Ruby functors are not the same thing a Haskell functors. In Ruby, the
29-
Enumerator is most closely akin to Haskell's idea of a functor.
29+
We can also think of the Functor as an *anonymous/generic delegator*. Instead
30+
of having to create a specialized delegator class, a functor can be used instead.
31+
Functors are perfect when the delegation required is minimal.
32+
33+
**NOTE** Ruby functors are not the same thing a Haskell functors. In Ruby
34+
Enumerators are most akin to Haskell's idea of a functor.
35+
36+
37+
## Batteries Included
38+
39+
In addition to the Functor class, this library includes a dozen or so useful
40+
core extensions that take advantage of the power of the functor. Have a look
41+
at the demo directory for a rundown on the methods available and how they
42+
work.
3043

3144

3245
## Copyrights

0 commit comments

Comments
 (0)