ramda-ruby 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Ramda::Internal::CurriedMethod do
4
- let(:instance) { Class.new { extend Ramda::Internal::CurriedMethod } }
4
+ let(:klass) do
5
+ Class.new do
6
+ extend Ramda::Internal::CurriedMethod
7
+ include Ramda::Internal::Java::MakeCurryProc if RUBY_PLATFORM == 'java'
8
+ end
9
+ end
10
+ let(:instance) { klass.new }
5
11
 
6
12
  context '#curried_method' do
7
13
  it 'without placeholder' do
8
- instance.curried_method(:g) do |a, b, c|
14
+ klass.curried_method(:g) do |a, b, c|
9
15
  a + b + c
10
16
  end
11
17
 
@@ -17,7 +23,7 @@ describe Ramda::Internal::CurriedMethod do
17
23
  end
18
24
 
19
25
  it 'with placeholder' do
20
- instance.curried_method(:g) do |a, b, c|
26
+ klass.curried_method(:g) do |a, b, c|
21
27
  a + b + c
22
28
  end
23
29
 
@@ -33,7 +39,7 @@ describe Ramda::Internal::CurriedMethod do
33
39
 
34
40
  context 'exception handler' do
35
41
  before do
36
- instance.curried_method(:g) do |a, b, c|
42
+ klass.curried_method(:g) do |a, b, c|
37
43
  a + b + c
38
44
  end
39
45
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Ramda::List do
4
- let(:r) { described_class }
4
+ let(:r) { Ramda }
5
5
 
6
6
  context '#all' do
7
7
  it 'test' do
@@ -125,6 +125,20 @@ describe Ramda::List do
125
125
  end
126
126
  end
127
127
 
128
+ context '#drop_while' do
129
+ it 'from docs' do
130
+ lte_two = ->(x) { x <= 2 }
131
+
132
+ expect(R.drop_while(lte_two, [1, 2, 3, 4, 3, 2, 1])).to eq([3, 4, 3, 2, 1])
133
+ end
134
+
135
+ it 'is curried' do
136
+ drop_lt7 = R.drop_while(->(x) { x < 7 })
137
+ expect(drop_lt7.call([1, 3, 5, 7, 9])).to eq([7, 9])
138
+ expect(drop_lt7.call([2, 4, 6, 8, 10])).to eq([8, 10])
139
+ end
140
+ end
141
+
128
142
  context '#filter' do
129
143
  def is_even
130
144
  ->(n) { n.even? }
@@ -258,12 +272,34 @@ describe Ramda::List do
258
272
  end
259
273
  end
260
274
 
275
+ context '#init' do
276
+ it 'from docs' do
277
+ expect(R.init([1, 2, 3])).to eq([1, 2])
278
+ expect(R.init([1, 2])).to eq([1])
279
+ expect(R.init([1])).to eq([])
280
+ expect(R.init([])).to eq([])
281
+
282
+ expect(R.init('abc')).to eq('ab')
283
+ expect(R.init('ab')).to eq('a')
284
+ expect(R.init('a')).to eq('')
285
+ expect(R.init('')).to eq('')
286
+ end
287
+ end
288
+
261
289
  context '#insert' do
262
290
  it 'from docs' do
263
291
  expect(r.insert(2, 'x', [1, 2, 3, 4])).to eq([1, 2, 'x', 3, 4])
264
292
  end
265
293
  end
266
294
 
295
+ context '#insert_all' do
296
+ it 'from docs' do
297
+ xs = [1, 2, 3, 4]
298
+ expect(R.insert_all(2, ['x', 'y', 'z'], xs)).to eq([1, 2, 'x', 'y', 'z', 3, 4])
299
+ expect(xs).to eq([1, 2, 3, 4])
300
+ end
301
+ end
302
+
267
303
  context '#join' do
268
304
  it 'from docs' do
269
305
  expect(r.join('|', [1, 2, 3])).to eq('1|2|3')
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Ramda::Logic do
4
- let(:r) { described_class }
4
+ let(:r) { Ramda }
5
5
 
6
6
  it '#all_pass' do
7
7
  is_queen = R.prop_eq(:rank, 'Queen')
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Ramda::Math do
4
- let(:r) { described_class }
4
+ let(:r) { Ramda }
5
5
 
6
6
  context '#add' do
7
7
  it 'from docs' do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Ramda::Object do
4
- let(:r) { described_class }
4
+ let(:r) { Ramda }
5
5
 
6
6
  context '#assoc' do
7
7
  it 'from docs' do
@@ -109,6 +109,74 @@ describe Ramda::Object do
109
109
  end
110
110
  end
111
111
 
112
+ context '#evolve' do
113
+ it 'from docs' do
114
+ tomato = {
115
+ firstName: ' Tomato ',
116
+ data: {
117
+ elapsed: 100,
118
+ remaining: 1400
119
+ },
120
+ id: 123
121
+ }
122
+
123
+ transformations = {
124
+ firstName: R.trim,
125
+ lastName: R.trim, # Will not get invoked.
126
+ data: {
127
+ elapsed: R.add(1),
128
+ remaining: R.add(-1)
129
+ }
130
+ }
131
+
132
+ expect(R.evolve(transformations, tomato))
133
+ .to eq(firstName: 'Tomato', data: { elapsed: 101, remaining: 1399 }, id: 123)
134
+ end
135
+ end
136
+
137
+ context '#invert' do
138
+ it 'from docs' do
139
+ race_results_by_first_name = {
140
+ first: 'alice',
141
+ second: 'jake',
142
+ third: 'alice'
143
+ }
144
+ expect(R.invert(race_results_by_first_name))
145
+ .to eq('alice' => [:first, :third], 'jake' => [:second])
146
+ end
147
+
148
+ it 'returns an empty object when applied to a primitive' do
149
+ expect(R.invert(42)).to eq({})
150
+ expect(R.invert('abc')).to eq({})
151
+ expect(R.invert(nil)).to eq({})
152
+ end
153
+
154
+ it "returns the input's values as keys, and keys as values of an array" do
155
+ expect(R.invert([:a, :b, :c])).to eq(a: [0], b: [1], c: [2])
156
+ expect(R.invert(x: 'a', y: 'b', z: 'c')).to eq('a' => [:x], 'b' => [:y], 'c' => [:z])
157
+ end
158
+ end
159
+
160
+ context '#invert_obj' do
161
+ it 'from docs' do
162
+ race_results = {
163
+ first: 'alice',
164
+ second: 'jake',
165
+ third: 'alice'
166
+ }
167
+ expect(R.invert_obj(race_results)).to eq('alice' => :third, 'jake' => :second)
168
+
169
+ race_results = ['alice', 'jake', 'alice']
170
+ expect(R.invert_obj(race_results)).to eq('alice' => 2, 'jake' => 1)
171
+ end
172
+
173
+ it 'returns an empty object when applied to a primitive' do
174
+ expect(R.invert(42)).to eq({})
175
+ expect(R.invert('abc')).to eq({})
176
+ expect(R.invert(nil)).to eq({})
177
+ end
178
+ end
179
+
112
180
  context '#keys' do
113
181
  it 'from docs' do
114
182
  expect(r.keys(a: 1, b: 2, c: 3)).to eq([:a, :b, :c])
@@ -247,6 +315,37 @@ describe Ramda::Object do
247
315
  end
248
316
  end
249
317
 
318
+ context '#map_obj_indexed' do
319
+ def square_vowels(x, key, *)
320
+ vowels = [:a, :e, :i, :o, :u]
321
+ R.contains(key, vowels) ? x * x : x
322
+ end
323
+
324
+ it'works just like a normal mapObj' do
325
+ times2 = ->(x, *) { x * 2 }
326
+
327
+ expect(R.map_obj_indexed(times2, a: 1, b: 2, c: 3, d: 4))
328
+ .to eq(a: 2, b: 4, c: 6, d: 8)
329
+ end
330
+
331
+ it 'passes the index as a second parameter to the callback' do
332
+ add_indexed = ->(x, key, *) { [x, key].join }
333
+ expect(R.map_obj_indexed(add_indexed, a: 8, b: 6, c: 7, d: 5, e: 3, f: 0, g: 9))
334
+ .to eq(a: '8a', b: '6b', c: '7c', d: '5d', e: '3e', f: '0f', g: '9g')
335
+ end
336
+
337
+ it 'passes the entire list as a third parameter to the callback' do
338
+ expect(R.map_obj_indexed(method(:square_vowels), a: 8, b: 6, c: 7, d: 5, e: 3, f: 0, g: 9))
339
+ .to eq(a: 64, b: 6, c: 7, d: 5, e: 9, f: 0, g: 9)
340
+ end
341
+
342
+ it 'is curried' do
343
+ make_square_vowels = R.map_obj_indexed(method(:square_vowels))
344
+ expect(make_square_vowels.call(a: 8, b: 6, c: 7, d: 5, e: 3, f: 0, g: 9))
345
+ .to eq(a: 64, b: 6, c: 7, d: 5, e: 9, f: 0, g: 9)
346
+ end
347
+ end
348
+
250
349
  context '#merge' do
251
350
  it 'from docs' do
252
351
  expect(r.merge({ name: 'fred', age: 10 }, age: 40))
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Ramda::Relation do
4
- let(:r) { described_class }
4
+ let(:r) { Ramda }
5
5
 
6
6
  context '#equals' do
7
7
  it 'from docs' do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Ramda::String do
4
- let(:r) { described_class }
4
+ let(:r) { Ramda }
5
5
 
6
6
  context '#match' do
7
7
  it 'from docs' do
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Ramda::Type do
4
- let(:r) { described_class }
4
+ let(:r) { Ramda }
5
5
 
6
6
  context '#is' do
7
7
  it 'from docs' do
data/spec/ramda_spec.rb CHANGED
@@ -28,6 +28,7 @@ describe Ramda do
28
28
  r(:assoc_path)
29
29
  r(:binary)
30
30
  r(:bind)
31
+ r(:call)
31
32
  r(:chain)
32
33
  r(:clone)
33
34
  r(:comparator)
@@ -48,10 +49,12 @@ describe Ramda do
48
49
  r(:dissoc)
49
50
  r(:divide)
50
51
  r(:drop)
52
+ r(:drop_while)
51
53
  r(:empty)
52
54
  r(:eq_by)
53
55
  r(:eq_props)
54
56
  r(:equals)
57
+ r(:evolve)
55
58
  r(:filter)
56
59
  r(:find)
57
60
  r(:find_index)
@@ -71,8 +74,12 @@ describe Ramda do
71
74
  r(:if_else)
72
75
  r(:inc)
73
76
  r(:index_of)
77
+ r(:init)
74
78
  r(:insert)
79
+ r(:insert_all)
75
80
  r(:intersection)
81
+ r(:invert)
82
+ r(:invert_obj)
76
83
  r(:invoker)
77
84
  r(:is)
78
85
  r(:is_empty)
@@ -92,6 +99,7 @@ describe Ramda do
92
99
  r(:lt)
93
100
  r(:lte)
94
101
  r(:map)
102
+ r(:map_obj_indexed)
95
103
  r(:match)
96
104
  r(:max)
97
105
  r(:max_by)
@@ -105,6 +113,7 @@ describe Ramda do
105
113
  r(:negate)
106
114
  r(:not)
107
115
  r(:nth)
116
+ r(:nth_arg)
108
117
  r(:of)
109
118
  r(:omit)
110
119
  r(:once)
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,7 @@ require 'ramda'
3
3
  require 'pry'
4
4
 
5
5
  R = Ramda
6
+ R.debug_mode = true if ENV['RAMDA_DEBUG']
6
7
 
7
8
  require 'coveralls'
8
9
  Coveralls.wear!
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ramda-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vadim Lazebny
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-27 00:00:00.000000000 Z
11
+ date: 2017-07-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Ruby version of Ramda Js library.
14
14
  email:
@@ -21,18 +21,21 @@ extra_rdoc_files:
21
21
  - CHANGELOG.md
22
22
  - ROADMAP.md
23
23
  - docs/FUNCTIONS.md
24
+ - docs/RESOURCES.md
24
25
  files:
25
26
  - CHANGELOG.md
26
27
  - LICENSE.txt
27
28
  - README.md
28
29
  - ROADMAP.md
29
30
  - docs/FUNCTIONS.md
31
+ - docs/RESOURCES.md
30
32
  - lib/ramda.rb
31
33
  - lib/ramda/exception_handler.rb
32
34
  - lib/ramda/function.rb
33
35
  - lib/ramda/internal/curried_method.rb
34
36
  - lib/ramda/internal/function_with_arity.rb
35
37
  - lib/ramda/internal/functors.rb
38
+ - lib/ramda/internal/java/__make_curry_proc__.rb
36
39
  - lib/ramda/list.rb
37
40
  - lib/ramda/logic.rb
38
41
  - lib/ramda/math.rb