church 0.0.14 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -1
- data/church.gemspec +1 -0
- data/lib/church.rb +1 -1
- data/lib/church/array.rb +1 -34
- data/lib/church/utils.rb +3 -5
- data/lib/church/version.rb +1 -1
- data/spec/array_spec.rb +8 -0
- data/spec/math_spec.rb +1 -1
- data/spec/spec_helper.rb +3 -0
- metadata +18 -2
data/Gemfile
CHANGED
data/church.gemspec
CHANGED
data/lib/church.rb
CHANGED
data/lib/church/array.rb
CHANGED
@@ -4,32 +4,11 @@ module Church
|
|
4
4
|
coll == [] || coll == '' ? 0 : 1 + SIZE[coll[1..-1]]
|
5
5
|
}
|
6
6
|
|
7
|
-
# Returns the size of an array or string using iteration.
|
8
|
-
ISIZE = -> coll {
|
9
|
-
sz = 0
|
10
|
-
(slicer = -> {
|
11
|
-
sz += 1
|
12
|
-
(coll = coll[1..-1]) == [] || coll == '' ? sz : slicer[]
|
13
|
-
})[]
|
14
|
-
}
|
15
|
-
|
16
7
|
# Maps fn over coll recursively.
|
17
8
|
MAP = -> coll, &fn {
|
18
9
|
coll == [] ? [] : [fn[coll[0]]] + MAP[coll[1..-1], &fn]
|
19
10
|
}
|
20
11
|
|
21
|
-
# Maps fn over coll iteratively.
|
22
|
-
IMAP = -> coll, &fn {
|
23
|
-
sz = SIZE[coll]
|
24
|
-
ret = []
|
25
|
-
i = 0
|
26
|
-
|
27
|
-
(mapper = -> {
|
28
|
-
ret[i] = fn[coll[i]]
|
29
|
-
(i += 1) == sz ? ret : mapper[]
|
30
|
-
})[]
|
31
|
-
}
|
32
|
-
|
33
12
|
# Maps fn over coll iteratively and in-place, modifying the original collection.
|
34
13
|
MAP_BANG = -> coll, &fn {
|
35
14
|
sz = SIZE[coll]
|
@@ -58,18 +37,6 @@ module Church
|
|
58
37
|
coll == [] ? [] : (fn[coll[0]] ? [coll[0]] : []) + FILTER[coll[1..-1], &fn]
|
59
38
|
}
|
60
39
|
|
61
|
-
# Filters coll through fn using iteration.
|
62
|
-
IFILTER = -> coll, &fn {
|
63
|
-
sz = SIZE[coll]
|
64
|
-
ret = []
|
65
|
-
i = 0
|
66
|
-
|
67
|
-
(filterer = -> {
|
68
|
-
fn[coll[i]] ? ret << coll[i] : 0
|
69
|
-
(i += 1) == sz ? ret : filterer[]
|
70
|
-
})[]
|
71
|
-
}
|
72
|
-
|
73
40
|
# Performs fn with each element of coll in turn.
|
74
41
|
EACH = -> coll, &fn {
|
75
42
|
sz = SIZE[coll]
|
@@ -115,5 +82,5 @@ module Church
|
|
115
82
|
}
|
116
83
|
|
117
84
|
# Sorts the collection in reverse order.
|
118
|
-
RSORT =
|
85
|
+
RSORT = COMPOSE[REVERSE, SORT]
|
119
86
|
end
|
data/lib/church/utils.rb
CHANGED
@@ -8,11 +8,9 @@ module Church::Utils
|
|
8
8
|
|
9
9
|
# Returns its argument's Collatz sequence as an array
|
10
10
|
COLLATZ = -> n {
|
11
|
-
|
12
|
-
(collatz_p = -> {
|
11
|
+
(collatz_p = -> cs {
|
13
12
|
n = n % 2 == 0 ? n / 2 : n * 3 + 1
|
14
|
-
|
15
|
-
|
16
|
-
})[]
|
13
|
+
n == 1 ? cs << 1 : collatz_p[cs << n]
|
14
|
+
})[[n]]
|
17
15
|
}
|
18
16
|
end
|
data/lib/church/version.rb
CHANGED
data/spec/array_spec.rb
CHANGED
@@ -70,3 +70,11 @@ describe 'INDEXED' do
|
|
70
70
|
expect(INDEXED[[1, 2, 3]]).to eq [[1, 0], [2, 1], [3, 2]]
|
71
71
|
end
|
72
72
|
end
|
73
|
+
|
74
|
+
describe 'EACH' do
|
75
|
+
it "should perform fn for each element in coll" do
|
76
|
+
x = 0
|
77
|
+
EACH[[1, 2, 3], &-> n { x += n }]
|
78
|
+
expect(x).to be 6
|
79
|
+
end
|
80
|
+
end
|
data/spec/math_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
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.1.0
|
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-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: simplecov
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.7.1
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.7.1
|
46
62
|
description:
|
47
63
|
email:
|
48
64
|
- 3ifbyw@gmail.com
|