Top Level Namespace

Defined Under Namespace

Modules: TreeSitter, TreeStand

Instance Method Summary collapse

Instance Method Details

#array_split_like_rust(array, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/tree_sitter/helpers.rb', line 4

def array_split_like_rust(array, &block)
  return enum_for(__method__, array) if !block_given?

  return [] if array.empty?

  result = []
  current_slice = []

  array.each do |element|
    if yield(element)
      result << current_slice
      current_slice = []
    else
      current_slice << element
    end
  end

  result << current_slice
  result
end