refinements 8.1.1 → 8.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
  SHA256:
3
- metadata.gz: c04df598103624b71b08d5b175c319d21c9fa5ff773976c5956f6e1aa0acdb70
4
- data.tar.gz: d6b9d57e2a23a74d1bed6e98146590e1bdc4f4a843ea9ed72747b6ccd3d847bc
3
+ metadata.gz: 5706b329caaea4cbf42c9dd34d8da325d5e4b5628385a760de2ca4b4c5efaf06
4
+ data.tar.gz: c20a4aad691df3a683d3ea29d58ae0dbcef4475d297460a945874c2298972864
5
5
  SHA512:
6
- metadata.gz: 996ac02a62679e6cd2bd083863ee587d9915a65bee40883bb21875a196d79126eacae345458f4e5f784203e9d26af17a8735c46a6c3e2eacf77adecacea07d08
7
- data.tar.gz: 5a4d11cb1010fbe61137b5e0382568bec9bdb4812d169f68d749e2e9809a033109102631a1568030eef53b6372e5bda4a23d93b3ceb7cef0f164f6b5e9b6a91d
6
+ metadata.gz: d14f810b454fe4e3116dc35b04a3701485b9ddad99889db58da96cec8e8556271ec53292447861748909add9d293a21a7c3c7a49fc16720fd61f7654dc2251a4
7
+ data.tar.gz: 61defc07d39c9de58db72ae0f937319694d156c6a0ed2896f6c2a9b645bfbb5fd829e01e96c242764cb4115dc030dbb5ffcb8010446cec34316b7666b62f8061
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/README.adoc CHANGED
@@ -135,6 +135,23 @@ Removes given array or elements without mutating itself.
135
135
  [1, 2, 3, 4, 5].excluding 4, 5 # => [1, 2, 3]
136
136
  ----
137
137
 
138
+ ===== #filter_find
139
+
140
+ Answers the first truthy and filtered result from a collection.
141
+
142
+ [source,ruby]
143
+ ----
144
+ handlers = [
145
+ ->(object) { object if object == :b },
146
+ proc { false },
147
+ ->(object) { object if object == :a }
148
+ ]
149
+
150
+ handlers.filter_find # => Enumerator::Lazy
151
+ handlers.filter_find { |handler| handler.call :a } # => :a
152
+ handlers.filter_find { |handler| handler.call :x } # => nil
153
+ ----
154
+
138
155
  ===== #including
139
156
 
140
157
  Adds given array or elements without mutating itself.
@@ -156,6 +173,19 @@ Inserts additional elements or array between all members of given array.
156
173
  [1, 2, 3].intersperse %i[a b c] # => [1, :a, :b, :c, 2, :a, :b, :c, 3]
157
174
  ----
158
175
 
176
+ ===== #maximum
177
+
178
+ Answers the maximum extracted value from a collection of objects.
179
+
180
+ [source,ruby]
181
+ ----
182
+ Point = Struct.new :x, :y, keyword_init: true
183
+ points = [Point[x: 1, y: 2], Point[x: 0, y: 1], Point[x: 2, y: 3]]
184
+
185
+ points.maximum(:x) # => 2
186
+ points.maximum(:y) # => 3
187
+ ----
188
+
159
189
  ===== #mean
160
190
 
161
191
  Answers mean/average all elements within an array.
@@ -168,6 +198,19 @@ Answers mean/average all elements within an array.
168
198
  [1.25, 1.5, 1.75].mean # => 1.5
169
199
  ----
170
200
 
201
+ ===== #minimum
202
+
203
+ Answers the minimum extracted value from a collection of objects.
204
+
205
+ [source,ruby]
206
+ ----
207
+ Point = Struct.new :x, :y, keyword_init: true
208
+ points = [Point[x: 1, y: 2], Point[x: 0, y: 1], Point[x: 2, y: 3]]
209
+
210
+ points.minimum(:x) # => 0
211
+ points.minimum(:y) # => 1
212
+ ----
213
+
171
214
  ===== #pad
172
215
 
173
216
  Answers new array padded with given value up to a maximum size. Useful in situations where an array
@@ -9,12 +9,18 @@ module Refinements
9
9
 
10
10
  def excluding(*elements) = self - elements.flatten
11
11
 
12
+ def filter_find(&block) = block ? lazy.map(&block).find(&:itself) : lazy
13
+
12
14
  def including(*elements) = self + elements.flatten
13
15
 
14
16
  def intersperse(*elements) = product([elements]).tap(&:pop).flatten.push(last)
15
17
 
18
+ def maximum(key) = map(&key).max
19
+
16
20
  def mean = size.zero? ? 0 : sum(0) / size
17
21
 
22
+ def minimum(key) = map(&key).min
23
+
18
24
  def pad(value, max: size) = dup.fill(value, size..(max - 1))
19
25
 
20
26
  def ring(&block) = [last, *self, first].each_cons(3, &block)
@@ -5,7 +5,7 @@ module Refinements
5
5
  module Identity
6
6
  NAME = "refinements"
7
7
  LABEL = "Refinements"
8
- VERSION = "8.1.1"
8
+ VERSION = "8.2.0"
9
9
  VERSION_LABEL = "#{LABEL} #{VERSION}"
10
10
  end
11
11
  end
@@ -21,9 +21,7 @@ module Refinements
21
21
  def revalue attributes = each_pair
22
22
  return self unless block_given?
23
23
 
24
- dup.tap do |copy|
25
- attributes.each { |key, value| copy[key] = yield self[key], value }
26
- end
24
+ dup.tap { |copy| attributes.each { |key, value| copy[key] = yield self[key], value } }
27
25
  end
28
26
 
29
27
  def revalue! attributes = each_pair
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refinements
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.1.1
4
+ version: 8.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -28,7 +28,7 @@ cert_chain:
28
28
  lkHilIrX69jq8wMPpBhlaw2mRmeSL50Wv5u6xVBvOHhXFSP1crXM95vfLhLyRYod
29
29
  W2A=
30
30
  -----END CERTIFICATE-----
31
- date: 2021-04-18 00:00:00.000000000 Z
31
+ date: 2021-05-25 00:00:00.000000000 Z
32
32
  dependencies: []
33
33
  description:
34
34
  email:
@@ -75,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
75
75
  - !ruby/object:Gem::Version
76
76
  version: '0'
77
77
  requirements: []
78
- rubygems_version: 3.2.16
78
+ rubygems_version: 3.2.17
79
79
  signing_key:
80
80
  specification_version: 4
81
81
  summary: A collection of refinements to core Ruby objects.
metadata.gz.sig CHANGED
Binary file