Method: Array#take_while

Defined in:
lib/ruby/jruby_hack.rb

#take_while(accumulator = [], &block) ⇒ Array

Takes the longest prefix of elements that satisfy the predicate.

Returns:



133
134
135
136
137
138
139
140
# File 'lib/ruby/jruby_hack.rb', line 133

def take_while(accumulator = [], &block)
  # This is in tail call form
  if not empty? and yield(head)
    tail.take_while(head.snoc(accumulator), &block)
  else
    accumulator
  end
end