We have an Enumerator::Lazy object
a = [1,2,3].lazy.map {} #=> <Enumerator::Lazy: #<Enumerator::Lazy: [1, 2, 3]>:map>
a.size #=> 3
a.clone.size #=> nil
Does anyone have correct explanation of such behaviour ? I know that size
returns size of the enumerator, or nil if it can’t be calculated lazily.
When we clone object it returns
a.clone #=> <Enumerator::Lazy:<Enumerator::Generator:0x00007fdaa80218d8>:each>
size
for aEnumerator
is not necessarily a real thing ( or atleast not what one would think it is) which may be the reason this change was implemented.For example
or better still
This seems to be a change in 2.4 where it appears that it reverts back to the :each method (possibly through
enum_for
) because in 2.3 the reference tomap
is retained as is the size. Obviously due to the reversion no iteration has occurred and size cannot be determine in a "lazy" fashion and thusnil