summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--enumerator.c21
2 files changed, 25 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 22ba3c84fd..4c9a7f6385 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Tue Mar 13 00:09:18 2012 Shugo Maeda <shugo@ruby-lang.org>
+
+ * enumerator.c (enumerable_lazy): added documentation.
+
Mon Mar 12 20:19:25 2012 Tanaka Akira <akr@fsij.org>
* lib/tmpdir.rb (Dir::tmpdir): test the current directory suitable for
diff --git a/enumerator.c b/enumerator.c
index 8e02021386..5e91673899 100644
--- a/enumerator.c
+++ b/enumerator.c
@@ -1247,6 +1247,27 @@ lazy_initialize(VALUE self, VALUE obj)
/*
* 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)