funkify 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +14 -7
- data/lib/funkify.rb +1 -1
- data/lib/funkify/version.rb +1 -1
- data/spec/funkify_spec.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d5d368db1d50577c1cf79227015a65bfa6c89d02
|
4
|
+
data.tar.gz: 819c4d262056e8c8c2fbd4e37eeb3d822681e4f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1c249b9939eabca11d0221377aff41e2c59951c4980ab6e54e30f5ca1561bc0117c949429c43ade6a5de0a32a64651759eda7915c7857f9ab26466f5003a5f8
|
7
|
+
data.tar.gz: 5948d58b24e0c4deaf5a397f4daf672531263b952aef994400f12ac775a5f41a2284996c39b8795321203f3e9a1bb5d02a9bf35656f22d77785d8c44d148c6dc
|
data/README.md
CHANGED
@@ -1,9 +1,16 @@
|
|
1
1
|
# Funkify
|
2
2
|
|
3
|
-
**(c) Copyright 2013, Epitron**
|
4
|
-
|
5
3
|
_Haskell-style partial application and composition for Ruby methods_
|
6
4
|
|
5
|
+
|
6
|
+
"In computer science, partial application refers to the process of
|
7
|
+
fixing a number of arguments to a function, producing another function of smaller arity."
|
8
|
+
--[Wikipedia](http://en.wikipedia.org/wiki/Partial_application)
|
9
|
+
|
10
|
+
[Partial application in haskell](http://www.haskell.org/haskellwiki/Partial_application)<br>
|
11
|
+
[Function composition in haskell](http://www.haskell.org/haskellwiki/Function_composition)
|
12
|
+
|
13
|
+
|
7
14
|
## Usage
|
8
15
|
|
9
16
|
```ruby
|
@@ -42,15 +49,15 @@ add_1 = funky.add(1) #=> The `1` is partially applied and a `Proc` is returned
|
|
42
49
|
add_1.(2) #=> We invoke that `Proc` with the remaining argument and the final result (`3`) is returned.
|
43
50
|
```
|
44
51
|
|
45
|
-
We can also compose methods using
|
52
|
+
We can also compose methods using `*`:
|
46
53
|
|
47
54
|
```ruby
|
48
|
-
add_1_and_multiply_by_5 = funky.mult(5)
|
55
|
+
add_1_and_multiply_by_5 = funky.mult(5) * funky.add(1)
|
49
56
|
add_1_and_multiply_by_5.(10) #=> 55
|
50
57
|
|
51
58
|
# We can even further compose the above with another method:
|
52
59
|
|
53
|
-
(funky.negate
|
60
|
+
(funky.negate * add_1_and_multiply_by_5).(10) #=> -55
|
54
61
|
```
|
55
62
|
|
56
63
|
Other examples:
|
@@ -58,13 +65,13 @@ Other examples:
|
|
58
65
|
Add 10 to every item in an Enumerable:
|
59
66
|
|
60
67
|
```ruby
|
61
|
-
(1..5).map
|
68
|
+
(1..5).map &funky.add(10) #=> [11, 12, 13, 14, 15]
|
62
69
|
```
|
63
70
|
|
64
71
|
Multiply by 10 and negate every item in an Enumerable:
|
65
72
|
|
66
73
|
```ruby
|
67
|
-
(1..5).map &(funky.negate
|
74
|
+
(1..5).map &(funky.negate * funky.mult(10)) => [-10, -20, -30, -40, -50]
|
68
75
|
```
|
69
76
|
|
70
77
|
## Installation
|
data/lib/funkify.rb
CHANGED
data/lib/funkify/version.rb
CHANGED
data/spec/funkify_spec.rb
CHANGED
@@ -106,19 +106,19 @@ describe Funkify do
|
|
106
106
|
end
|
107
107
|
|
108
108
|
it 'returns a new Proc when composing methods' do
|
109
|
-
(@c.negate
|
109
|
+
(@c.negate * @c.plus_1).is_a?(Proc).should == true
|
110
110
|
end
|
111
111
|
|
112
112
|
it 'invokes composed methods in the correct order (right-to-left)' do
|
113
|
-
(@c.negate
|
113
|
+
(@c.negate * @c.plus_1).(5).should == -6
|
114
114
|
end
|
115
115
|
|
116
116
|
it 'can compose partially applied methods' do
|
117
|
-
(@c.add(5)
|
117
|
+
(@c.add(5) * @c.mult(2)).(5).should == 15
|
118
118
|
end
|
119
119
|
|
120
120
|
it 'can compose multiple methods' do
|
121
|
-
(@c.negate
|
121
|
+
(@c.negate * @c.add(5) * @c.mult(5)).(5).should == -30
|
122
122
|
end
|
123
123
|
end
|
124
124
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: funkify
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Mair
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-07-
|
11
|
+
date: 2013-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|