ramda-ruby 0.1.4 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e9fde33339db665f8cc1bd20ba439d490de4ced5
4
- data.tar.gz: 89a420e74940dd7bf124ba9a1da690eefa7de2ea
3
+ metadata.gz: f971edce60a0eb897c51802fc1df7d23fb4f53ca
4
+ data.tar.gz: 32fd85ab6bb177addb2664eb2ac576583667388c
5
5
  SHA512:
6
- metadata.gz: 4cd815afc079d285f8485f3e4c62ec436a49b40f1c489bce0fc80b11fc0b8771ea23090c100431f2a4ba8f6da6c92be9e2a3f52aee74768e99031db58830854c
7
- data.tar.gz: e71938b6211936c3880d60bc3119e84e11d1bbe3f16579b79c87cec63fe8f661a0682af9d3746dccf9056ae17c1ddca0bd22ea66138da08203f8dc42c772039c
6
+ metadata.gz: a580a96ae672b59301ef1518437d4bd67da8771df6e0ed02690485658ccb1b3693e7e96c777760b1e3cf940b57ad580e9eeb7fdec2d5351bea004eaecff6cee5
7
+ data.tar.gz: 37e0c16db0f2dbf232cc7cd5f45ef0db9a86117b99af3421c4228dc1ae73fcb645693a9c46162f4f4b4ace576304205e45192bd4d12aa240df6f4c6662063e11
data/CHANGELOG.md CHANGED
@@ -1,6 +1,18 @@
1
1
  Not Released
2
2
  ---------------
3
3
 
4
+ Release 0.2.0
5
+ ---------------
6
+
7
+ Added:
8
+
9
+ * binary
10
+ * path
11
+ * unary
12
+ * uniq_with - first argument is a function with 1 arity which transforms each list element and applies uniq function to results
13
+ * (pending) keys_in
14
+ * (pending) values_in
15
+
4
16
  Release 0.1.4
5
17
  ---------------
6
18
 
@@ -14,13 +26,14 @@ Added:
14
26
  Release 0.1.1
15
27
  ---------------
16
28
 
17
- Breaking changes: index_of, last_index_of return nil instead of -1 if element can't be found
29
+ Breaking changes: index_of, last_index_of return nil instead of -1 if element
30
+ can't be found
18
31
 
19
32
  Added:
20
33
 
21
- * find_index
34
+ * find_index - returns nil if index doesn't exist
22
35
  * find_last
23
- * find_last_index
36
+ * find_last_index - returns nil if index doesn't exist
24
37
  * for_each
25
38
  * modulo
26
39
  * repeat
@@ -28,4 +41,5 @@ Added:
28
41
 
29
42
  Release 0.1.0
30
43
  ---------------
44
+
31
45
  Added functions from Ramda Js v0.1.0
data/ROADMAP.md CHANGED
@@ -2,15 +2,6 @@
2
2
 
3
3
  * Find out suitable documentation format
4
4
 
5
- ### release 0.2.0
6
-
7
- binary
8
- keys_in
9
- path
10
- unary
11
- uniq_with
12
- values_in
13
-
14
5
  ### release 0.2.2
15
6
 
16
7
  insert
data/docs/FUNCTIONS.md CHANGED
@@ -1,3 +1,5 @@
1
+ * (pending) keys_in
2
+ * (pending) values_in
1
3
  * add
2
4
  * all
3
5
  * all_pass
@@ -7,6 +9,7 @@
7
9
  * any_pass
8
10
  * append
9
11
  * assoc
12
+ * binary
10
13
  * clone
11
14
  * comparator
12
15
  * compose
@@ -27,12 +30,9 @@
27
30
  * equals
28
31
  * filter
29
32
  * find
30
- * find_index
31
- * find_index
33
+ * find_index - returns nil if index doesn't exist
32
34
  * find_last
33
- * find_last
34
- * find_last_index
35
- * find_last_index
35
+ * find_last_index - returns nil if index doesn't exist
36
36
  * flatten
37
37
  * flip
38
38
  * for_each
@@ -43,7 +43,7 @@
43
43
  * identity
44
44
  * if_else
45
45
  * inc
46
- * index_of
46
+ * index_of - returns nil if index doesn't exist
47
47
  * intersection
48
48
  * invoker
49
49
  * is_empty
@@ -52,7 +52,7 @@
52
52
  * juxt
53
53
  * keys
54
54
  * last
55
- * last_index_of
55
+ * last_index_of - returns nil if index doesn't exist
56
56
  * length
57
57
  * lt
58
58
  * lte
@@ -71,6 +71,7 @@
71
71
  * once
72
72
  * or
73
73
  * partition
74
+ * path
74
75
  * pick
75
76
  * pick_all
76
77
  * pipe
@@ -99,9 +100,11 @@
99
100
  * tap
100
101
  * to_lower
101
102
  * to_upper
103
+ * unary
102
104
  * union
103
105
  * union_with
104
106
  * uniq
107
+ * uniq_with - first argument is a function with 1 arity which transforms each list element and applies uniq function to results
105
108
  * use_with
106
109
  * values
107
110
  * where
data/lib/ramda.rb CHANGED
@@ -17,6 +17,7 @@ module Ramda
17
17
 
18
18
  def_delegators Ramda::Function,
19
19
  :always,
20
+ :binary,
20
21
  :comparator,
21
22
  :compose,
22
23
  :construct,
@@ -31,6 +32,7 @@ module Ramda
31
32
  :once,
32
33
  :pipe,
33
34
  :tap,
35
+ :unary,
34
36
  :use_with
35
37
 
36
38
  def_delegators Ramda::List,
@@ -71,6 +73,7 @@ module Ramda
71
73
  :take,
72
74
  :take_while,
73
75
  :uniq,
76
+ :uniq_with,
74
77
  :xprod,
75
78
  :zip,
76
79
  :zip_with
@@ -102,14 +105,17 @@ module Ramda
102
105
  :dissoc,
103
106
  :eq_props,
104
107
  :keys,
108
+ # :keys_in,
105
109
  :merge,
106
110
  :omit,
111
+ :path,
107
112
  :pick,
108
113
  :pick_all,
109
114
  :project,
110
115
  :prop,
111
116
  :props,
112
117
  :values,
118
+ # :values_in,
113
119
  :where
114
120
 
115
121
  def_delegators Ramda::Relation,
@@ -10,6 +10,15 @@ module Ramda
10
10
  -> { value }
11
11
  end
12
12
 
13
+ # Wraps a function of any arity (including nullary) in a function that
14
+ # accepts exactly 2 parameters. Any extraneous parameters will not be
15
+ # passed to the supplied function.
16
+ #
17
+ #
18
+ curried_method(:binary) do |fn|
19
+ n_ary(2, fn)
20
+ end
21
+
13
22
  # Makes a comparator function out of a function that reports whether
14
23
  # the first element is less than the second.
15
24
  #
@@ -170,6 +179,16 @@ module Ramda
170
179
  x
171
180
  end
172
181
 
182
+ # Wraps a function of any arity (including nullary) in a function that
183
+ # accepts exactly 1 parameter. Any extraneous parameters will not be passed
184
+ # to the supplied function.
185
+ #
186
+ # (* -> b) -> (a -> b)
187
+ #
188
+ curried_method(:unary) do |fn|
189
+ n_ary(1, fn)
190
+ end
191
+
173
192
  # Accepts a function fn and a list of transformer functions and returns
174
193
  # a new curried function. When the new function is invoked, it calls the
175
194
  # function fn with parameters consisting of the result of calling each
data/lib/ramda/list.rb CHANGED
@@ -408,6 +408,13 @@ module Ramda
408
408
  #
409
409
  curried_method(:uniq, &:uniq)
410
410
 
411
+ # Returns a new list containing only one copy of each element in the original list,
412
+ # based upon the value returned by applying the supplied predicate to each list
413
+ # element.
414
+ curried_method(:uniq_with) do |fn, xs|
415
+ xs.uniq(&fn)
416
+ end
417
+
411
418
  # Creates a new list out of the two supplied by creating each possible pair
412
419
  # from the lists.
413
420
  #
data/lib/ramda/object.rb CHANGED
@@ -56,6 +56,19 @@ module Ramda
56
56
  #
57
57
  curried_method(:keys, &:keys)
58
58
 
59
+ # Returns a list containing the names of all the properties of the supplied
60
+ # object, including prototype properties.
61
+ #
62
+ # {k: v} -> [k]
63
+ #
64
+ curried_method(:keys_in) do |obj|
65
+ (obj.methods - obj.class.methods)
66
+ .map(&:to_s)
67
+ .reject { |r| r.include?('=') }
68
+ .map(&:to_sym)
69
+ .uniq
70
+ end
71
+
59
72
  # Create a new object with the own properties of the first object merged
60
73
  # with the own properties of the second object. If a key exists in both
61
74
  # objects, the value from the second object will be used.
@@ -76,6 +89,15 @@ module Ramda
76
89
  obj_copy
77
90
  end
78
91
 
92
+ # Retrieve the value at a given path.
93
+ #
94
+ # [Idx] -> {a} -> a | NilClass
95
+ # Idx = String | Int
96
+ #
97
+ curried_method(:path) do |keys, obj|
98
+ keys.reduce(obj) { |acc, key| acc.is_a?(Hash) ? acc.fetch(key, nil) : nil }
99
+ end
100
+
79
101
  # Returns a partial copy of an object containing only the keys specified.
80
102
  # If the key does not exist, the property is ignored.
81
103
  #
@@ -126,6 +148,15 @@ module Ramda
126
148
  #
127
149
  curried_method(:values, &:values)
128
150
 
151
+ # Returns a list of all the properties, including prototype properties,
152
+ # of the supplied object.
153
+ #
154
+ # {k: v} -> [v]
155
+ #
156
+ curried_method(:values_in) do |obj|
157
+ keys_in(obj).map(&obj.method(:send))
158
+ end
159
+
129
160
  # Takes a spec object and a test object; returns true if the test satisfies
130
161
  # the spec. Each of the spec's own properties must be a predicate function.
131
162
  # Each predicate is applied to the value of the corresponding property of
data/lib/ramda/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Ramda
2
- VERSION = '0.1.4'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
@@ -15,6 +15,16 @@ describe Ramda::Function do
15
15
  end
16
16
  end
17
17
 
18
+ context '#binary' do
19
+ it 'from docs' do
20
+ takes_three_args = ->(a, b, c) { [a, b, c]; }
21
+ expect(takes_three_args.call(1, 2, 3)).to eq([1, 2, 3])
22
+
23
+ takes_two_args = r.binary(takes_three_args)
24
+ expect(takes_two_args.call(1, 2, 3)).to eq([1, 2, nil])
25
+ end
26
+ end
27
+
18
28
  context '#comparator' do
19
29
  it 'from docs' do
20
30
  sort_rule = r.comparator(->(a, b) { a < b })
@@ -194,6 +204,16 @@ describe Ramda::Function do
194
204
  end
195
205
  end
196
206
 
207
+ context '#unary' do
208
+ it 'from docs' do
209
+ takes_two_args = ->(a, b) { [a, b] }
210
+ expect(takes_two_args.call(1, 2)).to eq([1, 2])
211
+
212
+ takes_one_args = r.unary(takes_two_args)
213
+ expect(takes_one_args.call(1, 2)).to eq([1, nil])
214
+ end
215
+ end
216
+
197
217
  context '#use_with' do
198
218
  it 'from docs' do
199
219
  pow = ->(x, count) { Array.new(count, x).reduce(:*) }
@@ -449,6 +449,16 @@ describe Ramda::List do
449
449
  end
450
450
  end
451
451
 
452
+ context '#uniq_with' do
453
+ it 'from docs' do
454
+ str_eq = R.invoker(0, 'to_s')
455
+ expect(r.uniq_with(str_eq).call([1, '1', 2, 1])).to eq([1, 2])
456
+ expect(r.uniq_with(str_eq).call([{}, {}])).to eq([{}])
457
+ expect(r.uniq_with(str_eq).call([1, '1', 1])).to eq([1])
458
+ expect(r.uniq_with(str_eq).call(['1', 1, 1])).to eq(['1'])
459
+ end
460
+ end
461
+
452
462
  context '#xprod' do
453
463
  it 'from docs' do
454
464
  expect(r.xprod([1, 2], ['a', 'b']))
@@ -47,6 +47,20 @@ describe Ramda::Object do
47
47
  end
48
48
  end
49
49
 
50
+ xcontext '#keys_in' do
51
+ it 'from docs' do
52
+ obj = Class.new do |_x, _y|
53
+ attr_reader :x
54
+ attr_accessor :y
55
+ attr_writer :z
56
+
57
+ def test; end
58
+ end.new
59
+
60
+ expect(r.keys_in(obj)).to eq([:x, :y])
61
+ end
62
+ end
63
+
50
64
  context '#merge' do
51
65
  it 'from docs' do
52
66
  expect(r.merge({ name: 'fred', age: 10 }, age: 40))
@@ -66,6 +80,13 @@ describe Ramda::Object do
66
80
  end
67
81
  end
68
82
 
83
+ context '#path' do
84
+ it 'from docs' do
85
+ expect(r.path([:a, :b], a: { b: 2 })).to eq(2)
86
+ expect(r.path([:a, :b], c: { b: 2 })).to eq(nil)
87
+ end
88
+ end
89
+
69
90
  context '#pick' do
70
91
  it 'from docs' do
71
92
  expect(r.pick([:a, :d], a: 1, b: 2, c: 3, d: 4)).to eq(a: 1, d: 4)
@@ -115,6 +136,25 @@ describe Ramda::Object do
115
136
  end
116
137
  end
117
138
 
139
+ xcontext '#values_in' do
140
+ it 'from docs' do
141
+ obj = Class.new do |_x, _y|
142
+ def initialize(x)
143
+ @x = x
144
+ end
145
+
146
+ attr_reader :x
147
+ attr_accessor :y
148
+ attr_writer :z
149
+
150
+ def test; end
151
+ end.new(100)
152
+ obj.y = 1000
153
+
154
+ expect(r.values_in(obj)).to eq([100, 1000])
155
+ end
156
+ end
157
+
118
158
  context '#where' do
119
159
  it 'from docs' do
120
160
  pred = R.where(a: R.equals('foo'),
data/spec/ramda_spec.rb CHANGED
@@ -58,6 +58,7 @@ describe Ramda do
58
58
  r(:join)
59
59
  r(:juxt)
60
60
  r(:keys)
61
+ # r(:keys_in)
61
62
  r(:last)
62
63
  r(:last_index_of)
63
64
  r(:length)
@@ -78,6 +79,7 @@ describe Ramda do
78
79
  r(:once)
79
80
  r(:or)
80
81
  r(:partition)
82
+ r(:path)
81
83
  r(:pick)
82
84
  r(:pick_all)
83
85
  r(:pipe)
@@ -106,11 +108,14 @@ describe Ramda do
106
108
  r(:tap)
107
109
  r(:to_lower)
108
110
  r(:to_upper)
111
+ r(:unary)
109
112
  r(:union)
110
113
  r(:union_with)
111
114
  r(:uniq)
115
+ r(:uniq_with)
112
116
  r(:use_with)
113
117
  r(:values)
118
+ # r(:values_in)
114
119
  r(:where)
115
120
  r(:xprod)
116
121
  r(:zip)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ramda-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vadim Lazebny