static VALUE lazy_zip(int argc, VALUE *argv, VALUE obj) { VALUE ary, v; long i; rb_block_call_func *func = lazy_zip_arrays_func; if (rb_block_given_p()) { return rb_call_super(argc, argv); } ary = rb_ary_new2(argc); for (i = 0; i < argc; i++) { v = rb_check_array_type(argv[i]); if (NIL_P(v)) { for (; i < argc; i++) { if (!rb_respond_to(argv[i], id_each)) { rb_raise(rb_eTypeError, "wrong argument type %s (must respond to :each)", rb_obj_classname(argv[i])); } } ary = rb_ary_new4(argc, argv); func = lazy_zip_func; break; } rb_ary_push(ary, v); } return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj, func, ary), ary, lazy_receiver_size); }
static VALUE lazy_take_while(VALUE obj) { return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj, lazy_take_while_func, 0), Qnil); }
static VALUE lazy_grep(VALUE obj, VALUE pattern) { return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj, rb_block_given_p() ? lazy_grep_iter : lazy_grep_func, pattern), rb_ary_new3(1, pattern), 0); }
static VALUE lazy_drop_while(VALUE obj) { if (!rb_block_given_p()) { rb_raise(rb_eArgError, "tried to call lazy drop_while without a block"); } return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj, lazy_drop_while_func, 0), Qnil, 0); }
static VALUE lazy_drop_while(VALUE obj) { NODE *memo; memo = NEW_MEMO(0, 0, FALSE); return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj, lazy_drop_while_func, (VALUE) memo), Qnil); }
static VALUE lazy_map(VALUE obj) { if (!rb_block_given_p()) { rb_raise(rb_eArgError, "tried to call lazy map without a block"); } return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj, lazy_map_func, 0), Qnil, lazy_receiver_size); }
static VALUE lazy_reject(VALUE obj) { if (!rb_block_given_p()) { rb_raise(rb_eArgError, "tried to call lazy reject without a block"); } return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj, lazy_reject_func, 0), Qnil); }
static VALUE lazy_drop(VALUE obj, VALUE n) { long len = NUM2LONG(n); if (len < 0) { rb_raise(rb_eArgError, "attempt to drop negative size"); } return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj, lazy_drop_func, n), rb_ary_new3(1, n), lazy_drop_size); }
static VALUE lazy_drop(VALUE obj, VALUE n) { NODE *memo; long len = NUM2LONG(n); if (len < 0) { rb_raise(rb_eArgError, "attempt to drop negative size"); } memo = NEW_MEMO(0, 0, len); return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj, lazy_drop_func, (VALUE) memo), rb_ary_new3(1, n)); }
static VALUE lazy_zip(int argc, VALUE *argv, VALUE obj) { VALUE ary; int i; if (rb_block_given_p()) { return rb_call_super(argc, argv); } ary = rb_ary_new2(argc); for (i = 0; i < argc; i++) { rb_ary_push(ary, rb_funcall(argv[i], id_lazy, 0)); } return lazy_set_method(rb_block_call(rb_cLazy, id_new, 1, &obj, lazy_zip_func, ary), rb_ary_new4(argc, argv)); }
static VALUE lazy_take(VALUE obj, VALUE n) { long len = NUM2LONG(n); VALUE lazy; if (len < 0) { rb_raise(rb_eArgError, "attempt to take negative size"); } if (len == 0) { VALUE len = INT2FIX(0); lazy = lazy_to_enum_i(obj, sym_cycle, 1, &len, 0); } else { lazy = rb_block_call(rb_cLazy, id_new, 1, &obj, lazy_take_func, n); } return lazy_set_method(lazy, rb_ary_new3(1, n), lazy_take_size); }
static VALUE lazy_cycle(int argc, VALUE *argv, VALUE obj) { VALUE args; int len = rb_long2int((long)argc + 2); if (rb_block_given_p()) { return rb_call_super(argc, argv); } args = rb_ary_tmp_new(len); rb_ary_push(args, obj); rb_ary_push(args, sym_cycle); if (argc > 0) { rb_ary_cat(args, argv, argc); } return lazy_set_method(rb_block_call(rb_cLazy, id_new, len, RARRAY_PTR(args), lazy_cycle_func, args /* prevent from GC */), rb_ary_new4(argc, argv)); }
static VALUE lazy_take(VALUE obj, VALUE n) { NODE *memo; long len = NUM2LONG(n); int argc = 1; VALUE argv[3]; if (len < 0) { rb_raise(rb_eArgError, "attempt to take negative size"); } argv[0] = obj; if (len == 0) { argv[1] = sym_cycle; argv[2] = INT2NUM(0); argc = 3; } memo = NEW_MEMO(0, 0, len); return lazy_set_method(rb_block_call(rb_cLazy, id_new, argc, argv, lazy_take_func, (VALUE) memo), rb_ary_new3(1, n)); }