ree_lib 1.0.109 → 1.0.110

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
  SHA256:
3
- metadata.gz: f2c475acec8b61f3686477e9ae4643427b3f956c8abb2ae8fe6c4d8e8ebb2c82
4
- data.tar.gz: 0a2138c853bd35f2340a9469b960e0c2cad3f89e4fdc4662692661048c9a3638
3
+ metadata.gz: 0b8df95664f84438cd5e7c9b32c9f942bb4d39f3cf8c498d5da9ef3ee018bcdc
4
+ data.tar.gz: c76b3c8f4edc5995b77dcc3be2fbdeb84a6145113b9709de45e3b0c72c6e8bb0
5
5
  SHA512:
6
- metadata.gz: bb6bab53e49f860719f7b342df2500a16f5ce97e431cc2e96d04df39bdc749521a5f639f4d0d6f6b3068ed840e35adaa5144847805b8a5254d12e3969f36c566
7
- data.tar.gz: 1bb7d488e89e1c5824012f6e1cde805bcc1d5bd095515c0e90608fca7995884115b2053fd6527306c0d6476884601c2d446b445260cabc46229e9e73cc8d11e4
6
+ metadata.gz: 76bc804c35d55a01a1819ec2a71648277c7dd722892774456f5cc8dfdabbbc98b4870535fca3a7fecd8d43a4d52091fb4bd4091ac906310d633089e7dfb135c8
7
+ data.tar.gz: 69e33d02056be8fa3150c30489f4b35bb425788e5eb75afb7b71067fd7eafd9fa1231a3463a713f480276e2b5d3c37f8f82b2828ad65d156a204708cc2296e92
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ree_lib (1.0.109)
4
+ ree_lib (1.0.110)
5
5
  bigdecimal (~> 3.1.6)
6
6
  binding_of_caller (~> 1.0.0)
7
7
  i18n (~> 1.14.1)
@@ -6,7 +6,7 @@ class ReeArray::GroupBy
6
6
  fn :group_by
7
7
 
8
8
  contract(
9
- ArrayOf[Any], Block => HashOf[Any, ArrayOf[Any]]
9
+ Or[ArrayOf[Any], Enumerable], Block => HashOf[Any, ArrayOf[Any]]
10
10
  )
11
11
  def call(list, &proc)
12
12
  result = {}
@@ -8,24 +8,24 @@ class ReeArray::InGroups
8
8
  doc(<<~DOC)
9
9
  Splits or iterates over the array in +number+ of groups, padding any
10
10
  remaining slots with +fill_with+ unless it is +false+.
11
-
11
+
12
12
  in_groups(%w(1 2 3 4 5 6 7 8 9 10), 3, fill_with: nil) {|group| p group}
13
13
  ["1", "2", "3", "4"]
14
14
  ["5", "6", "7", nil]
15
15
  ["8", "9", "10", nil]
16
-
16
+
17
17
  in_groups(%w(1 2 3 4 5 6 7 8 9 10, 3, fill_with: '&nbsp;') {|group| p group}
18
18
  ["1", "2", "3", "4"]
19
19
  ["5", "6", "7", "&nbsp;"]
20
20
  ["8", "9", "10", "&nbsp;"]
21
-
21
+
22
22
  in_groups(%w(1 2 3 4 5 6 7), 3) {|group| p group}
23
23
  ["1", "2", "3"]
24
24
  ["4", "5"]
25
25
  ["6", "7"]
26
26
  DOC
27
27
  contract(
28
- ArrayOf[Any],
28
+ Or[ArrayOf[Any], Enumerable],
29
29
  Integer,
30
30
  Ksplat[fill_with?: Any],
31
31
  Optblock => Or[ArrayOf[Any], Any]
@@ -8,25 +8,25 @@ class ReeArray::InGroupsOf
8
8
  doc(<<~DOC)
9
9
  Splits or iterates over the array in groups of size +number+,
10
10
  padding any remaining slots with +fill_with+ unless it is +false+.
11
-
11
+
12
12
  in_groups_of(%w(1 2 3 4 5 6 7 8 9 10), 3, fill_with: nil) {|group| p group}
13
13
  ["1", "2", "3"]
14
14
  ["4", "5", "6"]
15
15
  ["7", "8", "9"]
16
16
  ["10", nil, nil]
17
-
17
+
18
18
  in_groups_of(%w(1 2 3 4 5), 2, fill_with: '&nbsp;') {|group| p group}
19
19
  ["1", "2"]
20
20
  ["3", "4"]
21
21
  ["5", "&nbsp;"]
22
-
22
+
23
23
  in_groups_of(%w(1 2 3 4 5), 2) {|group| p group}
24
24
  ["1", "2"]
25
25
  ["3", "4"]
26
26
  ["5"]
27
27
  DOC
28
28
  contract(
29
- ArrayOf[Any],
29
+ Or[ArrayOf[Any], Enumerable],
30
30
  Integer,
31
31
  Ksplat[fill_with?: Any],
32
32
  Optblock => Or[ArrayOf[Any], ArrayOf[ArrayOf[Any]]]
@@ -5,7 +5,7 @@ class ReeArray::IndexBy
5
5
 
6
6
  fn :index_by
7
7
 
8
- contract(ArrayOf[Any], Block => Hash)
8
+ contract(Or[ArrayOf[Any], Enumerable], Block => Hash)
9
9
  def call(list, &proc)
10
10
  result = {}
11
11
  list.each { result[yield(_1)] = _1 }
@@ -8,11 +8,11 @@ class ReeArray::SplitBy
8
8
  doc(<<~DOC)
9
9
  Divides the array into one or more subarrays based on a delimiting +value+
10
10
  or the result of an optional block.
11
-
11
+
12
12
  split([1, 2, 3, 4, 5], 3) # => [[1, 2], [4, 5]]
13
13
  split((1..10).to_a) { |i| i % 3 == 0 } # => [[1, 2], [4, 5], [7, 8], [10]]
14
14
  DOC
15
- contract(ArrayOf[Any], Any, Optblock => ArrayOf[Any])
15
+ contract(Or[ArrayOf[Any], Enumerable], Any, Optblock => ArrayOf[Any])
16
16
  def call(array, value = nil, &block)
17
17
  arr = array.dup
18
18
  result = []
@@ -7,13 +7,13 @@ class ReeArray::Wrap
7
7
 
8
8
  doc(<<~DOC)
9
9
  Wraps its argument in an array unless it is already an array (or array-like).
10
-
10
+
11
11
  Specifically:
12
-
12
+
13
13
  * If the argument is +nil+ an empty array is returned.
14
14
  * Otherwise, if the argument responds to +to_ary+ it is invoked, and its result returned.
15
15
  * Otherwise, returns an array with the argument as its single element.
16
-
16
+
17
17
  wrap(nil) # => []
18
18
  wrap([1, 2, 3]) # => [1, 2, 3]
19
19
  wrap(0) # => [0]
@@ -22,7 +22,7 @@ class ReeArray::Wrap
22
22
  def call(object)
23
23
  if object.nil?
24
24
  []
25
- elsif object.is_a?(Array)
25
+ elsif object.is_a?(Array) || object.is_a?(Enumerable)
26
26
  object
27
27
  else
28
28
  [object]
@@ -14,4 +14,35 @@ RSpec.describe :index_by do
14
14
  }
15
15
  )
16
16
  }
17
+
18
+ it {
19
+ class EnumerableArray
20
+ include Enumerable
21
+
22
+ def initialize
23
+ @list = []
24
+ end
25
+
26
+ def each(&proc)
27
+ @list.each &proc
28
+ end
29
+
30
+ def add(v)
31
+ @list << v
32
+ end
33
+ end
34
+
35
+ list = EnumerableArray.new
36
+ list.add({id: 1})
37
+ list.add({id: 2})
38
+
39
+ result = index_by(list) { _1[:id] }
40
+
41
+ expect(result).to eq(
42
+ {
43
+ 1 => {id: 1},
44
+ 2 => {id: 2}
45
+ }
46
+ )
47
+ }
17
48
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ReeLib
4
- VERSION = "1.0.109"
4
+ VERSION = "1.0.110"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ree_lib
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.109
4
+ version: 1.0.110
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruslan Gatiyatov