When the block passed to Lazy#flat_map returns a non-enumerable value
(e.g. an Integer), mruby raised NoMethodError because it unconditionally
called #each on the result. CRuby yields non-enumerable values directly.
Use respond_to?(:each) to match CRuby behavior: iterate enumerable
results, yield non-enumerable results as-is.
Added complete call-seq documentation for all lazy enumeration methods in
mrblib/lazy.rb (16 methods):
## Enumerable Extension Methods:
- lazy: creates Enumerator::Lazy for deferred evaluation, enables efficient
processing of infinite sequences and large datasets with comprehensive
pythagorean triples example demonstrating real-world usage
## Enumerator::Lazy Class Methods:
- new: constructor for creating lazy enumerators with custom yielding logic,
provides foundation for building custom lazy operations
- to_enum/enum_for: creates lazy enumerator from method calls, maintains
lazy evaluation chain for custom enumerable methods
## Enumerator::Lazy Instance Methods:
- map/collect: lazy transformation of elements with deferred execution
- select/find_all: lazy filtering with conditional element inclusion
- reject: lazy filtering with conditional element exclusion
- grep: lazy pattern matching using case equality operator
- grep_v: lazy inverse pattern matching for exclusion filtering
- drop: lazy skipping of first n elements without immediate evaluation
- drop_while: lazy conditional skipping until predicate fails
- take: lazy limiting to first n elements with automatic termination
- take_while: lazy conditional taking until predicate fails
- flat_map/collect_concat: lazy flattening and mapping in single operation
- zip: lazy combining of multiple enumerables into tuples
- uniq: lazy uniqueness filtering with optional transformation block
- force: immediate evaluation alias for to_a, converts lazy chain to array
Co-authored-by: Atlassian Rovo Dev
The issue #3920 was fixed but the fundamental flaw of lack of stack
depth check along with fibers still remains, even though it's not
easy to cause the issue. Use `MRB_GC_FIXED_ARENA` to avoid the issue
for workaround.
After this patch, `obj.to_enum` raises `ArgumentError` if the object
does not respond to the enumerating method. This is incompatible to
CRuby but I think this behavior is better and CRuby should be updated
to behave like this.