We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
a.chain(b)
a + b
.chain can link multiple Enumerables into a single efficient iterator.
# bad (a + b).map { |x| 42 + x } # good a.chain(b).map { |x| 42 + x }
Unlike +, it doesn't allocate an intermediate result:
+
require 'memory_profiler' a = (1..1000).to_a b = (1..1000).to_a MemoryProfiler.report { (a + b).map {} }.pretty_print MemoryProfiler.report { a.chain(b).map {} }.pretty_print
with +:
allocated memory by class ----------------------------------- 32080 Array
with chain:
chain
allocated memory by class ----------------------------------- 17784 Array 160 Proc 56 Enumerator::Chain
The text was updated successfully, but these errors were encountered:
No branches or pull requests
.chain can link multiple Enumerables into a single efficient iterator.
Unlike
+
, it doesn't allocate an intermediate result:with
+
:with
chain
:The text was updated successfully, but these errors were encountered: