aboutsummaryrefslogtreecommitdiffstats
path: root/enumerator.c
diff options
context:
space:
mode:
Diffstat (limited to 'enumerator.c')
-rw-r--r--enumerator.c21
1 files changed, 21 insertions, 0 deletions
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)