Sha256: b697bfeeffa600189e7e13cc7abfe5b878095ffeae5b32ca5a896169b6a4d3b1

Contents?: true

Size: 699 Bytes

Versions: 14

Compression:

Stored size: 699 Bytes

Contents

module Rbexy
  module Refinements
    module Array
      module MapTypeWhenNeighboringType
        refine ::Array do
          def map_type_when_neighboring_type(map_type, neighboring_type, &block)
            map.with_index do |curr, i|
              prev_i = i - 1
              next_i = i + 1

              if !curr.is_a?(map_type)
                curr
              elsif prev_i >= 0 && self[prev_i].is_a?(neighboring_type)
                block.call(curr)
              elsif next_i < length && self[next_i].is_a?(neighboring_type)
                block.call(curr)
              else
                curr
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rbexy-2.0.0.rc5 lib/rbexy/refinements/array/map_type_when_neighboring_type.rb
rbexy-2.0.0.rc4 lib/rbexy/refinements/array/map_type_when_neighboring_type.rb
rbexy-2.0.0.rc3 lib/rbexy/refinements/array/map_type_when_neighboring_type.rb
rbexy-2.0.0.rc2 lib/rbexy/refinements/array/map_type_when_neighboring_type.rb
rbexy-2.0.0.rc1 lib/rbexy/refinements/array/map_type_when_neighboring_type.rb
rbexy-2.0.0.beta9 lib/rbexy/refinements/array/map_type_when_neighboring_type.rb
rbexy-2.0.0.beta8 lib/rbexy/refinements/array/map_type_when_neighboring_type.rb
rbexy-2.0.0.beta7 lib/rbexy/refinements/array/map_type_when_neighboring_type.rb
rbexy-2.0.0.beta6 lib/rbexy/refinements/array/map_type_when_neighboring_type.rb
rbexy-2.0.0.beta5 lib/rbexy/refinements/array/map_type_when_neighboring_type.rb
rbexy-2.0.0.beta4 lib/rbexy/refinements/array/map_type_when_neighboring_type.rb
rbexy-2.0.0.beta3 lib/rbexy/refinements/array/map_type_when_neighboring_type.rb
rbexy-2.0.0.beta2 lib/rbexy/refinements/array/map_type_when_neighboring_type.rb
rbexy-2.0.0.beta1 lib/rbexy/refinements/array/map_type_when_neighboring_type.rb