church 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Church
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/church.png)](http://badge.fury.io/rb/church)
4
+ [![Build Status](https://travis-ci.org/threeifbywhiskey/church.png?branch=master)](https://travis-ci.org/threeifbywhiskey/church)
5
+
6
+
3
7
  **Church** is a module that wraps a bunch of constant Procs that do various functional programming tricks.
4
8
 
5
9
  ### Examples
data/church.gemspec CHANGED
@@ -17,7 +17,8 @@ Gem::Specification.new do |spec|
17
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
18
  spec.require_paths = ["lib"]
19
19
 
20
- spec.add_development_dependency "bundler", "~> 1.5"
20
+ spec.add_development_dependency "bundler"
21
21
  spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "rspec"
22
23
  spec.add_development_dependency "simplecov-console"
23
24
  end
data/lib/church/array.rb CHANGED
@@ -81,6 +81,14 @@ module Church
81
81
  SORT[FILTER[xs, &-> y { y >= x }]]
82
82
  }
83
83
 
84
+ SORT_BY = -> coll, &fn {
85
+ x, *xs = *coll
86
+ coll == [] ? []
87
+ : SORT_BY[FILTER[xs, &-> y { (fn[x] <=> fn[y]) == 1 }], &fn] +
88
+ [x] +
89
+ SORT_BY[FILTER[xs, &-> y { (fn[x] <=> fn[y]) <= 0 }], &fn]
90
+ }
91
+
84
92
  # Sorts the collection in reverse order.
85
93
  RSORT = COMPOSE[REVERSE, SORT]
86
94
 
@@ -89,4 +97,11 @@ module Church
89
97
 
90
98
  # Returns the first n elements of the collection.
91
99
  TAKE = -> coll, n { coll[0, n] }
100
+
101
+ # Returns the index of the element within the collection, or nil if not found.
102
+ INDEX = -> coll, elem {
103
+ (indexer = -> i {
104
+ coll[i] == elem ? i : i > SIZE[elem] ? nil : indexer[i + 1]
105
+ })[0]
106
+ }
92
107
  end
@@ -1,3 +1,3 @@
1
1
  module Church
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.4"
3
3
  end
data/spec/array_spec.rb CHANGED
@@ -59,6 +59,14 @@ describe 'SORT' do
59
59
  end
60
60
  end
61
61
 
62
+ describe 'SORT_BY' do
63
+ let(:order) { [1, 2, 3, 4, 5] }
64
+
65
+ it "should sort an array using the supplied function" do
66
+ expect(SORT_BY[[4, 2, 5, 1, 3], &-> n { order.index n }]).to eq order
67
+ end
68
+ end
69
+
62
70
  describe 'RSORT' do
63
71
  it "should sort an array in reverse order" do
64
72
  expect(RSORT[[2, 1, 3]]).to eq [3, 2, 1]
@@ -90,3 +98,10 @@ describe 'TAKE' do
90
98
  expect(TAKE[[1, 2, 3, 4], 2]).to eq [1, 2]
91
99
  end
92
100
  end
101
+
102
+ describe 'INDEX' do
103
+ it "should find the indices of characters within strings" do
104
+ expect(INDEX['abc', 'b']).to be 1
105
+ expect(INDEX['abc', 'd']).to be nil
106
+ end
107
+ 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.1.2
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -16,17 +16,17 @@ dependencies:
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '1.5'
21
+ version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  none: false
26
26
  requirements:
27
- - - ~>
27
+ - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
- version: '1.5'
29
+ version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: rake
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -43,6 +43,22 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
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'
46
62
  - !ruby/object:Gem::Dependency
47
63
  name: simplecov-console
48
64
  requirement: !ruby/object:Gem::Requirement