church 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
data/lib/church/hash.rb CHANGED
@@ -1,8 +1,11 @@
1
1
  module Church
2
+ # Returns the keys of a Hash as an array
2
3
  KEYS = -> hash { MAP[[*hash], &:first] }
3
4
 
5
+ # Returns the values of a Hash as an array
4
6
  VALUES = -> hash { MAP[[*hash], &:last] }
5
7
 
8
+ # Inverts the keys and values of its hash argument
6
9
  INVERT = -> hash {
7
10
  ks, vs = KEYS[hash], VALUES[hash]
8
11
  sz = SIZE[ks]
@@ -15,6 +18,7 @@ module Church
15
18
  })[]
16
19
  }
17
20
 
21
+ # Merges the keys and values of the two hashes into a new hash
18
22
  MERGE = -> a, b {
19
23
  all = [*a] + [*b]
20
24
  sz = SIZE[all]
data/lib/church/io.rb CHANGED
@@ -1,16 +1,21 @@
1
1
  module Church
2
+ # Returns the equivalent of Fixnum#chr
2
3
  CHR = -> o { '' << o }
3
4
 
5
+ # Returns the equivalent of String#ord
4
6
  ORD = -> c {
5
7
  (order = -> i {
6
8
  '' << i == c ? i : order[i + 1]
7
9
  })[1]
8
10
  }
9
11
 
12
+ # Prints the object
10
13
  PRINT = -> obj { $> << obj }
11
14
 
15
+ # Prints the object with a newline
12
16
  PUTS = -> obj { $> << obj << "\n" }
13
17
 
18
+ # Returns an array of the characters of a string
14
19
  CHARS = -> str {
15
20
  sz = SIZE[str]
16
21
  ret = []
@@ -22,5 +27,6 @@ module Church
22
27
  })[]
23
28
  }
24
29
 
25
- JOIN = -> str, delim { str * delim }
30
+ # Joins the collection into a string on a specified delimiter
31
+ JOIN = -> coll, delim { coll * delim }
26
32
  end
data/lib/church/lambda.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  module Church
2
+ # Composes the lambdas f and g into a procedure which returns f(g(x))
2
3
  COMPOSE = -> f, g { -> x { f[g[x]] } }
3
4
  end
data/lib/church/math.rb CHANGED
@@ -1,8 +1,11 @@
1
1
  module Church
2
+ # Returns the square root of its argument
2
3
  SQRT = -> n { n ** 2 ** -1 }
3
4
 
5
+ # Returns its argument rounded down
4
6
  FLOOR = -> n { n - n % 1 }
5
7
 
8
+ # Returns the primality of its argument
6
9
  PRIME = -> n {
7
10
  n = n < 0 ? -n : n
8
11
  n < 3 ? n == 2 : n % 2 == 0 ? false :
data/lib/church/utils.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  module Church::Utils
2
+ # Returns the ROT-13 of the specified character
2
3
  ROT13 = -> chr {
3
4
  ord = ORD[chr]
4
5
  ord > 64 && ord < 91 ? CHR[(ord - 78) % 26 + 65] :
@@ -1,3 +1,3 @@
1
1
  module Church
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
data/spec/io_spec.rb CHANGED
@@ -3,18 +3,14 @@ require 'spec_helper'
3
3
  include Church
4
4
 
5
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
6
+ it "should return its argument's corresponding character" do
7
+ expect(CHR[83]).to eq 83.chr
10
8
  end
11
9
  end
12
10
 
13
11
  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
12
+ it "should return its argument's corresponding ordinal value" do
13
+ expect(ORD['q']).to be 'q'.ord
18
14
  end
19
15
  end
20
16
 
data/spec/lambda_spec.rb CHANGED
@@ -7,7 +7,7 @@ describe 'COMPOSE' do
7
7
  MUL_SIX = -> x { 6 * x }
8
8
  SIX_X_PLUS_TWO = COMPOSE[ADD_TWO, MUL_SIX]
9
9
 
10
- (-50..50).each do |x|
10
+ (-2..2).each do |x|
11
11
  it "should compose two lambdas f and g and return f[g[x]]" do
12
12
  expect(SIX_X_PLUS_TWO[x]).to be x * 6 + 2
13
13
  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
- (-25..25).each do |i|
19
+ (-6..6).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/utils_spec.rb CHANGED
@@ -7,4 +7,9 @@ describe 'ROT13' do
7
7
  expect(ROT13['a']).to eq 'n'
8
8
  expect(ROT13['n']).to eq 'a'
9
9
  end
10
+
11
+ it "should rotate an uppercase letter 13 places" do
12
+ expect(ROT13['M']).to eq 'Z'
13
+ expect(ROT13['Z']).to eq 'M'
14
+ end
10
15
  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.11
4
+ version: 0.0.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: