lib/jumoku/ext/ext.rb
# Fetches the positions of Branch items in an array,
# and expands them in place as nodes pairs.
#
#     expand_branches!(1,2, Branch.new(2, 3), 3,4, 4,5)
#     # => 1,2, 2,3, 3,4, 4,5
#
# @param [*nodes, *Branch] *a a flat list of nodes pairs and branches
# @return [*nodes] a flat list of nodes pairs
Fetches the positions of Branch items in an array,
and expands them in place as nodes pairs.


Fetches the positions of Branch items in an array and expands them in place as nodes pairs .
def expand_branches!
    branches_positions = self.dup.map_send(:"is_a?", Jumoku::Branch).map_with_index { |e,i| i if e == true }.compact
    branches_positions = branches_positions.map_with_index { |e,i| e += i }
    branches_positions.each do |pos|
      branch = self.delete_at pos
      self.insert pos,   branch.source
      self.insert pos+1, branch.target
    end
    return self
  end
def expand_branches! branches_positions = self . dup . map_send ( :" is_a? " , Jumoku :: Branch ) . map_with_index { | e , i | i if e == true } . compact branches_positions = branches_positions . map_with_index { | e , i | e += i } branches_positions . each do | pos | branch = self . delete_at pos self . insert pos , branch . source self . insert pos + 1 , branch . target end return self end
Fetches the positions of Branch items in an array,
and expands them in place as nodes pairs.
Fetches the positions of Branch items in an array and expands them in place as nodes pairs .
# obviously positions will gain an offset of 1 for each expanded branch, # so let's correct this right away
a flat list of nodes pairs
a flat list of nodes pairs
*nodes
<not_specific>
a a flat list of nodes pairs and branches
a a flat list of nodes pairs and branches