church 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/lib/church/array.rb +7 -0
- data/lib/church/range.rb +1 -0
- data/lib/church/version.rb +1 -1
- data/spec/array_spec.rb +10 -0
- metadata +1 -1
data/README.md
CHANGED
@@ -18,4 +18,4 @@ EACH[[1, 2, 3], &-> e { p e } ]
|
|
18
18
|
|
19
19
|
### Why?
|
20
20
|
|
21
|
-
The point of writing everything using Procs, for me at least, is to eventually transform programs into [non-alphanumeric](threeifbywhiskey.github.io/2014/03/05/non-alphanumeric-ruby-for-fun-and-not-much-else/) versions of themselves. Church's design goal is to make that an easier process.
|
21
|
+
The point of writing everything using Procs, for me at least, is to eventually transform programs into [non-alphanumeric](https://threeifbywhiskey.github.io/2014/03/05/non-alphanumeric-ruby-for-fun-and-not-much-else/) versions of themselves. Church's design goal is to make that an easier process.
|
data/lib/church/array.rb
CHANGED
@@ -103,4 +103,11 @@ module Church
|
|
103
103
|
coll[i] == elem ? i : i > SIZE[coll] ? nil : indexer[i + 1]
|
104
104
|
})[0]
|
105
105
|
}
|
106
|
+
|
107
|
+
# Returns the product of two arrays
|
108
|
+
PRODUCT = -> a, b {
|
109
|
+
REDUCE[MAP[[*0...SIZE[a]],
|
110
|
+
&-> x { MAP[[*0...SIZE[b]],
|
111
|
+
&-> y { [a[x], b[y]] }] }], &:+]
|
112
|
+
}
|
106
113
|
end
|
data/lib/church/range.rb
CHANGED
data/lib/church/version.rb
CHANGED
data/spec/array_spec.rb
CHANGED
@@ -122,3 +122,13 @@ describe 'INDEX' do
|
|
122
122
|
expect(INDEX[[1, 2, 3], 4]).to be nil
|
123
123
|
end
|
124
124
|
end
|
125
|
+
|
126
|
+
describe 'PRODUCT' do
|
127
|
+
let(:a) { [1, 2, :potato] }
|
128
|
+
let(:b) { [3, 4] }
|
129
|
+
|
130
|
+
it "should return the product of two arrays" do
|
131
|
+
expect(PRODUCT[a, b]).to eq a.product b
|
132
|
+
expect(PRODUCT[b, a]).to eq b.product a
|
133
|
+
end
|
134
|
+
end
|