[前][次][番号順一覧][スレッド一覧]

ruby-changes:22940

From: shugo <ko1@a...>
Date: Tue, 13 Mar 2012 00:12:22 +0900 (JST)
Subject: [ruby-changes:22940] shugo:r34989 (trunk): * enumerator.c (enumerable_lazy): added the documenation of Enumerable#lazy.

shugo	2012-03-13 00:12:07 +0900 (Tue, 13 Mar 2012)

  New Revision: 34989

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34989

  Log:
    * enumerator.c (enumerable_lazy): added the documenation of Enumerable#lazy.

  Modified files:
    trunk/ChangeLog
    trunk/enumerator.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 34988)
+++ ChangeLog	(revision 34989)
@@ -1,3 +1,7 @@
+Tue Mar 13 00:09:18 2012  Shugo Maeda  <shugo@r...>
+
+	* enumerator.c (enumerable_lazy): added documentation.
+
 Mon Mar 12 20:19:25 2012  Tanaka Akira  <akr@f...>
 
 	* lib/tmpdir.rb (Dir::tmpdir): test the current directory suitable for
Index: enumerator.c
===================================================================
--- enumerator.c	(revision 34988)
+++ enumerator.c	(revision 34989)
@@ -1247,6 +1247,27 @@
 /*
  * call-seq:
  *   e.lazy -> lazy_enumerator
+ *
+ * Returns a lazy enumerator, whose methods map/collect,
+ * flat_map/collect_concat, select/find_all, reject, and grep call blocks
+ * only on an as-needed basis.
+ *
+ * === Example
+ *
+ * The following program shows all pythagorean triples less than 100:
+ *
+ *   def pythagorean_triples
+ *     (1..Float::INFINITY).lazy.flat_map {|z|
+ *       (1..z).flat_map {|x|
+ *         (x..z).select {|y|
+ *           x**2 + y**2 == z**2
+ *         }.map {|y|
+ *           [x, y, z]
+ *         }
+ *       }
+ *     }
+ *   end
+ *   p pythagorean_triples.take_while { |x, y, z| z < 100 }
  */
 static VALUE
 enumerable_lazy(VALUE obj)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]