rudash 2.10.0 → 2.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rudash/group_by.rb +20 -0
- data/lib/rudash.rb +2 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d280372231ea9f4063e975606d64e77bdaa28634fa4fcc27d12c8ea089b09a6
|
4
|
+
data.tar.gz: 916fcebb70f983689f53965a77ce312b8542b4754a5ecdf145b74d93989f9f03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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.
|
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
|