refinements 8.1.1 → 8.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.adoc +43 -0
- data/lib/refinements/arrays.rb +6 -0
- data/lib/refinements/identity.rb +1 -1
- data/lib/refinements/structs.rb +1 -3
- metadata +3 -3
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5706b329caaea4cbf42c9dd34d8da325d5e4b5628385a760de2ca4b4c5efaf06
|
4
|
+
data.tar.gz: c20a4aad691df3a683d3ea29d58ae0dbcef4475d297460a945874c2298972864
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
data/lib/refinements/arrays.rb
CHANGED
@@ -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)
|
data/lib/refinements/identity.rb
CHANGED
data/lib/refinements/structs.rb
CHANGED
@@ -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
|
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.
|
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-
|
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.
|
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
|