README.adoc in refinements-8.1.1 vs README.adoc in refinements-8.2.0

- old
+ new

@@ -133,10 +133,27 @@ ---- [1, 2, 3, 4, 5].excluding [4, 5] # => [1, 2, 3] [1, 2, 3, 4, 5].excluding 4, 5 # => [1, 2, 3] ---- +===== #filter_find + +Answers the first truthy and filtered result from a collection. + +[source,ruby] +---- +handlers = [ + ->(object) { object if object == :b }, + proc { false }, + ->(object) { object if object == :a } +] + +handlers.filter_find # => Enumerator::Lazy +handlers.filter_find { |handler| handler.call :a } # => :a +handlers.filter_find { |handler| handler.call :x } # => nil +---- + ===== #including Adds given array or elements without mutating itself. [source,ruby] @@ -154,19 +171,45 @@ [1, 2, 3].intersperse :a # => [1, :a, 2, :a, 3] [1, 2, 3].intersperse :a, :b # => [1, :a, :b, 2, :a, :b, 3] [1, 2, 3].intersperse %i[a b c] # => [1, :a, :b, :c, 2, :a, :b, :c, 3] ---- +===== #maximum + +Answers the maximum extracted value from a collection of objects. + +[source,ruby] +---- +Point = Struct.new :x, :y, keyword_init: true +points = [Point[x: 1, y: 2], Point[x: 0, y: 1], Point[x: 2, y: 3]] + +points.maximum(:x) # => 2 +points.maximum(:y) # => 3 +---- + ===== #mean Answers mean/average all elements within an array. [source,ruby] ---- [].mean # => 0 [5].mean # => 5 [1, 2, 3].mean # => 2 [1.25, 1.5, 1.75].mean # => 1.5 +---- + +===== #minimum + +Answers the minimum extracted value from a collection of objects. + +[source,ruby] +---- +Point = Struct.new :x, :y, keyword_init: true +points = [Point[x: 1, y: 2], Point[x: 0, y: 1], Point[x: 2, y: 3]] + +points.minimum(:x) # => 0 +points.minimum(:y) # => 1 ---- ===== #pad Answers new array padded with given value up to a maximum size. Useful in situations where an array