instance method
Enumerator::Lazy#with_index
(?::Integer offset) { (Elem arg0, ::Integer arg1) -> untyped } -> Return
(?::Integer offset) -> ::Enumerator[[ Elem, ::Integer ], Return]
lazy.with_index(offset = 0) {|(*args), idx| block }
lazy.with_index(offset = 0)
enumerator.c
View on GitHub ↗
static VALUE
lazy_with_index(int argc, VALUE *argv, VALUE obj)
{
VALUE memo;
rb_scan_args(argc, argv, "01", &memo);
if (NIL_P(memo))
memo = LONG2NUM(0);
return lazy_add_method(obj, 0, 0, memo, rb_ary_new_from_values(1, &memo), &lazy_with_index_funcs);
}
If a block is given, returns a lazy enumerator that will iterate over the given block for each element with an index, which starts from offset, and returns a lazy enumerator that yields the same values (without the index).
If a block is not given, returns a new lazy enumerator that includes the index, starting from offset.
offset-
the starting index to use