Issue #4653 has been updated by Yusuke Endoh.

Status changed from Assigned to Rejected

??????????????? #4890 ????????????????????????????? (#708) ???
2/8 ??? Enumerable::Lazy ?念???

-- 
Yusuke Endoh <mame / tsg.ne.jp>
----------------------------------------
Feature #4653: [PATCH 1/1] new method Enumerable#rude_map
https://bugs.ruby-lang.org/issues/4653

Author: Shyouhei Urabe
Status: Rejected
Priority: Normal
Assignee: Yukihiro Matsumoto
Category: core
Target version: 2.0.0


From e6dd7bd9b5769bae5d81416da7a2b4003a43ba06 Mon Sep 17 00:00:00 2001
Message-Id: <e6dd7bd9b5769bae5d81416da7a2b4003a43ba06.1304863013.git.shyouhei / ruby-lang.org>
From: URABE, Shyouhei <shyouhei / ruby-lang.org>
Date: Sun, 8 May 2011 22:51:28 +0900
Subject: [PATCH 1/1] new method Enumerable#rude_map

??????????map???????????????????????????????????????????????????????????

?????????lzma???縮?????????????解??????????????大??????????????????????
?????????????????????????????解??????????????????????HTML escape??????
<pre></pre>????????????????????????????????lzma???縮?????????????????????
???????????(?:??)????????????????????????????HTML escape??????????
????????????????lzcat???popen????????????対??????
io.each_line.map.with_index.map. ... ?????????????????Ruby??????????
???????????????????????map???????????????????????????????????????費???????
???????????????????????????????Enumerator???????????????????????????????????????

???????????????map?????????????????????????????Enumerator???????map????種?????
????????????????????????????????????????????????1.9????????flat_map????????????
?????????_map????????????????????????????????????????????????????????
?????????????????????????map??????????????????????????????????????????
????????????????????????????????????

Signed-off-by: URABE, Shyouhei <shyouhei / ruby-lang.org>

diff --git a/enum.c b/enum.c
index 584b838..449406b 100644
--- a/enum.c
+++ b/enum.c
@@ -462,6 +462,41 @@ enum_flat_map(VALUE obj)
     return ary;
 }
 
+static VALUE
+rude_map_ii(VALUE i, VALUE y, int c, VALUE *v)
+{
+    return rb_funcall(y, rb_intern("<<"), 1, enum_yield(c, v));
+}
+
+static VALUE
+rude_map_i(VALUE y, VALUE i, int c, VALUE *v)
+{
+    return rb_block_call(i, id_each, 0, 0, rude_map_ii, y);
+}
+
+/*
+ *  call-seq:
+ *     enum.rude_map {| obj | block }  -> enumerator
+ *     enum.rude_map                   -> enumerator
+ *
+ *  Identical to Enumerable#map, except that it returns an enumerator
+ *  rather than an array.
+ *
+ *  Without a block it is just another Object#to_enum.
+ *
+ */
+
+static VALUE
+enum_rude_map(VALUE obj)
+{
+    VALUE ret;
+    RETURN_ENUMERATOR(obj, 0, 0);
+
+    ret = rb_obj_alloc(rb_cEnumerator);
+    rb_block_call(ret, rb_intern("initialize"), 0, 0, rude_map_i, obj);
+    return ret;
+}
+
 /*
  *  call-seq:
  *     enum.to_a      ->    array
@@ -2679,6 +2714,7 @@ Init_Enumerable(void)
     rb_define_method(rb_mEnumerable, "collect", enum_collect, 0);
     rb_define_method(rb_mEnumerable, "map", enum_collect, 0);
     rb_define_method(rb_mEnumerable, "flat_map", enum_flat_map, 0);
+    rb_define_method(rb_mEnumerable, "rude_map", enum_rude_map, 0);
     rb_define_method(rb_mEnumerable, "collect_concat", enum_flat_map, 0);
     rb_define_method(rb_mEnumerable, "inject", enum_inject, -1);
     rb_define_method(rb_mEnumerable, "reduce", enum_inject, -1);
-- 
1.7.0.4




-- 
http://bugs.ruby-lang.org/