rudash 2.10.0 → 2.11.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rudash/group_by.rb +20 -0
  3. data/lib/rudash.rb +2 -0
  4. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9093255b12cd834ff23fa463f4c7f2c4b0916a589c973c680cd4488149c9e6db
4
- data.tar.gz: 268185d416326b2e38ff02bb895e09625277a2a06c012b5af0938450886bf190
3
+ metadata.gz: 3d280372231ea9f4063e975606d64e77bdaa28634fa4fcc27d12c8ea089b09a6
4
+ data.tar.gz: 916fcebb70f983689f53965a77ce312b8542b4754a5ecdf145b74d93989f9f03
5
5
  SHA512:
6
- metadata.gz: 8d5f5e26667dccc7712a9127de99eb7a5a2fef6dc345e3e91972b3708c976b5e89f426f0766df0de4fd4ca1e94d4c4aa184e09b6610d588cdd724d3ea3caa6b3
7
- data.tar.gz: be2ffa703e19ffabf205a959e622b4db8bf457fbc9a35f7630cab5eb0af8179fd3b733c7e08e062886aff775dec77e08e81191da8fc58d7a84039beac7f503e5
6
+ metadata.gz: a9c3b7a12af7f445da8ada67271dcc637e8620a84352e5d0b7331f22bb26c39ba1c2375d97a339595d850f8c7566a1c11faf083a6ce6e84304025fdcdaa886b8
7
+ data.tar.gz: 4b7df53d6e1cff7365f358b11223e1ca746ce6f2c8dfab236ed3236b5a9d673f2571d46b70c66bbf046e1f15626d088e75e7068e2794b86b50641c51a38e5382
@@ -0,0 +1,20 @@
1
+ module Rudash
2
+ module GroupBy
3
+ def group_by(collection, iteratee = self.method(:identity))
4
+
5
+ reducer = -> (acc, current) {
6
+ key = Rudash::DynamicArgsCount.call(iteratee, current)
7
+
8
+ if acc[key]
9
+ acc[key] << current
10
+ else
11
+ acc[key] = [current]
12
+ end
13
+
14
+ acc
15
+ }
16
+
17
+ self.reduce(collection, reducer, {})
18
+ end
19
+ end
20
+ end
data/lib/rudash.rb CHANGED
@@ -45,6 +45,7 @@ require_relative './rudash/remove.rb'
45
45
  require_relative './rudash/union.rb'
46
46
  require_relative './rudash/reject.rb'
47
47
  require_relative './rudash/range.rb'
48
+ require_relative './rudash/group_by.rb'
48
49
 
49
50
  # This is the exposed Gem class that contains all Rudash methods.
50
51
  # New methods can use already implemented methods in the library by refering to "self"
@@ -97,4 +98,5 @@ class R_
97
98
  extend Rudash::Union
98
99
  extend Rudash::Reject
99
100
  extend Rudash::Range
101
+ extend Rudash::GroupBy
100
102
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rudash
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.10.0
4
+ version: 2.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Islam Attrash
@@ -32,6 +32,7 @@ files:
32
32
  - lib/rudash/find_last.rb
33
33
  - lib/rudash/flip.rb
34
34
  - lib/rudash/get.rb
35
+ - lib/rudash/group_by.rb
35
36
  - lib/rudash/head.rb
36
37
  - lib/rudash/identity.rb
37
38
  - lib/rudash/initial.rb