Module: JRuby::ScalaSupport::Seq::Common

Includes:
Common
Included in:
Immutable, Mutable
Defined in:
lib/jruby/scala_support.rb

Instance Method Summary collapse

Instance Method Details

#[](index) ⇒ Object



235
236
237
238
239
240
241
242
243
# File 'lib/jruby/scala_support.rb', line 235

def [](index)
  if index < 0
    @raw.apply(size + index).from_scala
  elsif index >= size
    nil
  else
    @raw.apply(index).from_scala
  end
end

#eachObject



245
246
247
248
249
250
251
252
253
254
255
256
257
# File 'lib/jruby/scala_support.rb', line 245

def each
  if block_given?
    @raw.foreach do |item|
      yield item.from_scala
    end
  else
    iterator = @raw.iterator

    Enumerator.new do |yielder|
      yielder << iterator.next.from_scala while iterator.hasNext
    end
  end
end

#to_sObject



259
260
261
262
263
264
265
# File 'lib/jruby/scala_support.rb', line 259

def to_s
  first = true
  each_with_object("[") do |item, str|
    first ? first = false : str << ", "
    str << item.to_s
  end << "]"
end