church 0.0.2 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +15 -1
- data/lib/church/array.rb +19 -0
- data/lib/church/io.rb +13 -0
- data/lib/church/version.rb +1 -1
- data/lib/church.rb +1 -0
- data/spec/array_spec.rb +12 -0
- data/spec/io_spec.rb +19 -0
- metadata +5 -2
data/README.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
1
|
# Church
|
2
2
|
|
3
|
-
|
3
|
+
**Church** is a module that wraps a bunch of constant Procs that do various functional programming tricks.
|
4
|
+
|
5
|
+
### Examples
|
6
|
+
|
7
|
+
``` ruby
|
8
|
+
MAP[[1, 2, 3], &-> c { c * 2 }]
|
9
|
+
```
|
10
|
+
|
11
|
+
``` ruby
|
12
|
+
EACH[[1, 2, 3], &-> e { p e } ]
|
13
|
+
```
|
14
|
+
|
15
|
+
### Why?
|
16
|
+
|
17
|
+
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.
|
data/lib/church/array.rb
CHANGED
@@ -80,4 +80,23 @@ module Church
|
|
80
80
|
(i += 1) == sz ? coll : eacher[]
|
81
81
|
})[]
|
82
82
|
}
|
83
|
+
|
84
|
+
INDEXED = -> coll {
|
85
|
+
sz = SIZE[coll]
|
86
|
+
ret = []
|
87
|
+
i = 0
|
88
|
+
|
89
|
+
(indexer = -> {
|
90
|
+
ret << [coll[i], i]
|
91
|
+
(i += 1) == sz ? ret : indexer[]
|
92
|
+
})[]
|
93
|
+
}
|
94
|
+
|
95
|
+
SORT = -> coll {
|
96
|
+
x, *xs = *coll
|
97
|
+
coll == [] ? []
|
98
|
+
: SORT[FILTER[xs, &-> y { y < x }]] +
|
99
|
+
[x] +
|
100
|
+
SORT[FILTER[xs, &-> y { y >= x }]]
|
101
|
+
}
|
83
102
|
end
|
data/lib/church/io.rb
ADDED
data/lib/church/version.rb
CHANGED
data/lib/church.rb
CHANGED
data/spec/array_spec.rb
CHANGED
@@ -42,3 +42,15 @@ describe 'FILTER' do
|
|
42
42
|
expect(FILTER[[1, 2, 3, 4], &:even?]).to eq [2, 4]
|
43
43
|
end
|
44
44
|
end
|
45
|
+
|
46
|
+
describe 'SORT' do
|
47
|
+
it "should sort an array" do
|
48
|
+
expect(SORT[[4, 3, 2, 2, 1, 3]]).to eq [1, 2, 2, 3, 3, 4]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'INDEXED' do
|
53
|
+
it "should zip a collection with indices" do
|
54
|
+
expect(INDEXED[[1, 2, 3]]).to eq [[1, 0], [2, 1], [3, 2]]
|
55
|
+
end
|
56
|
+
end
|
data/spec/io_spec.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Church
|
4
|
+
|
5
|
+
describe "CHR" do
|
6
|
+
(1..122).each do |ord|
|
7
|
+
it "should return its argument's corresponding character" do
|
8
|
+
expect(CHR[ord]).to eq ord.chr
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "ORD" do
|
14
|
+
("\1".."z").each do |chr|
|
15
|
+
it "should return its argument's corresponding ordinal value" do
|
16
|
+
expect(ORD[chr]).to be chr.ord
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: church
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-03-
|
12
|
+
date: 2014-03-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -58,9 +58,11 @@ files:
|
|
58
58
|
- church.gemspec
|
59
59
|
- lib/church.rb
|
60
60
|
- lib/church/array.rb
|
61
|
+
- lib/church/io.rb
|
61
62
|
- lib/church/math.rb
|
62
63
|
- lib/church/version.rb
|
63
64
|
- spec/array_spec.rb
|
65
|
+
- spec/io_spec.rb
|
64
66
|
- spec/math_spec.rb
|
65
67
|
- spec/spec_helper.rb
|
66
68
|
homepage: https://github.com/threeifbywhiskey/church
|
@@ -91,5 +93,6 @@ summary: Church provides top-level constant Procs to do various and sundry kinds
|
|
91
93
|
functional programming.
|
92
94
|
test_files:
|
93
95
|
- spec/array_spec.rb
|
96
|
+
- spec/io_spec.rb
|
94
97
|
- spec/math_spec.rb
|
95
98
|
- spec/spec_helper.rb
|