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 CHANGED
@@ -1,4 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in risper.gemspec
4
3
  gemspec
data/church.gemspec CHANGED
@@ -19,4 +19,5 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_development_dependency "bundler", "~> 1.5"
21
21
  spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "simplecov", "~> 0.7.1"
22
23
  end
data/lib/church.rb CHANGED
@@ -1,7 +1,7 @@
1
+ require 'church/lambda'
1
2
  require 'church/array'
2
3
  require 'church/hash'
3
4
  require 'church/io'
4
- require 'church/lambda'
5
5
  require 'church/math'
6
6
  require 'church/utils'
7
7
  require 'church/version'
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 = -> coll { REVERSE[SORT[coll]] }
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
- c = [n]
12
- (collatz_p = -> {
11
+ (collatz_p = -> cs {
13
12
  n = n % 2 == 0 ? n / 2 : n * 3 + 1
14
- c << n
15
- n == 1 ? c : collatz_p[]
16
- })[]
13
+ n == 1 ? cs << 1 : collatz_p[cs << n]
14
+ })[[n]]
17
15
  }
18
16
  end
@@ -1,3 +1,3 @@
1
1
  module Church
2
- VERSION = "0.0.14"
2
+ VERSION = "0.1.0"
3
3
  end
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
@@ -16,7 +16,7 @@ describe 'FLOOR' do
16
16
  end
17
17
 
18
18
  describe 'PRIME' do
19
- (-6..6).each do |i|
19
+ (-9..9).each do |i|
20
20
  it "should return its argument's primality" do
21
21
  expect(PRIME[i]).to be i.prime?
22
22
  end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,4 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+
1
4
  require File.expand_path('../../lib/church', __FILE__)
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.14
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-18 00:00:00.000000000 Z
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