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/