Sha256: 91b21f8ff4d5a054705c7bd595e1ea3d0a0d865e6668bb6bc10fee4729cd1e7f

Contents?: true

Size: 740 Bytes

Versions: 2

Compression:

Stored size: 740 Bytes

Contents

# frozen_string_literal: true

module Refinements
  module Arrays
    refine Array do
      def compress = compact.reject(&:empty?)

      def compress! = replace(compress)

      def excluding(*elements) = self - elements.flatten

      def filter_find(&block) = block ? lazy.map(&block).find(&:itself) : lazy

      def including(*elements) = self + elements.flatten

      def intersperse(*elements) = product([elements]).tap(&:pop).flatten.push(last)

      def maximum(key) = map(&key).max

      def mean = size.zero? ? 0 : sum(0.0) / size

      def minimum(key) = map(&key).min

      def pad(value, max: size) = dup.fill(value, size..(max - 1))

      def ring(&block) = [last, *self, first].each_cons(3, &block)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
refinements-8.2.2 lib/refinements/arrays.rb
refinements-8.2.1 lib/refinements/arrays.rb