Issue #7654 has been reported by shock_one (Володимир Шацький). ---------------------------------------- Feature #7654: Add optional code block to IO::readlines https://bugs.ruby-lang.org/issues/7654 Author: shock_one (Володимир Шацький) Status: Open Priority: Normal Assignee: Category: core Target version: Of course, we always can write something like File.readlines('/home/shock_one/test.rb').map{ |line| line.upcase } but this way we create unneeded intermediate array which can be pretty big. There is also a method IO::foreach, but it doesn't collect return values. Besides it seems pretty logical and natural to have a block in this method.
on 2013-01-04 14:15
on 2013-01-04 14:28
Issue #7654 has been updated by shock_one (Володимир Шацький).
Just to be clear: code block will allow to write the first code snippet
as follows:
data = File.readlines('/home/shock_one/test.rb'){ |line| line.upcase }
----------------------------------------
Feature #7654: Add optional code block to IO::readlines
https://bugs.ruby-lang.org/issues/7654#change-35207
Author: shock_one (Володимир Шацький)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version:
Of course, we always can write something like
File.readlines('/home/shock_one/test.rb').map{ |line| line.upcase }
but this way we create unneeded intermediate array which can be pretty
big.
There is also a method IO::foreach, but it doesn't collect return
values.
Besides it seems pretty logical and natural to have a block in this
method.
on 2013-01-04 15:38
Issue #7654 has been updated by Eregon (Benoit Daloze).
Why not
File.foreach('test.rb').map { |line| line.upcase }
?
It does not create an intermediary Array.
If you need to do other operations lazily (without an intermediate
result), you could use #lazy:
File.foreach('test.rb').lazy.select { |line| line.start_with? '/'
}.map { |line| line.upcase }.to_a
----------------------------------------
Feature #7654: Add optional code block to IO::readlines
https://bugs.ruby-lang.org/issues/7654#change-35210
Author: shock_one (Володимир Шацький)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version:
Of course, we always can write something like
File.readlines('/home/shock_one/test.rb').map{ |line| line.upcase }
but this way we create unneeded intermediate array which can be pretty
big.
There is also a method IO::foreach, but it doesn't collect return
values.
Besides it seems pretty logical and natural to have a block in this
method.
on 2013-01-04 15:45
Issue #7654 has been updated by Eregon (Benoit Daloze).
But of course the main memory usage here are likely String instances, so
you should update them in place if possible:
File.foreach('test.rb').map { |line| line.upcase!; line }
# or
lines = File.readlines('file.c')
lines.each(&:upcase!)
----------------------------------------
Feature #7654: Add optional code block to IO::readlines
https://bugs.ruby-lang.org/issues/7654#change-35211
Author: shock_one (Володимир Шацький)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version:
Of course, we always can write something like
File.readlines('/home/shock_one/test.rb').map{ |line| line.upcase }
but this way we create unneeded intermediate array which can be pretty
big.
There is also a method IO::foreach, but it doesn't collect return
values.
Besides it seems pretty logical and natural to have a block in this
method.
on 2013-01-04 15:49
Issue #7654 has been updated by Eregon (Benoit Daloze). (There is also Array#map!) ---------------------------------------- Feature #7654: Add optional code block to IO::readlines https://bugs.ruby-lang.org/issues/7654#change-35212 Author: shock_one (Володимир Шацький) Status: Open Priority: Normal Assignee: Category: core Target version: Of course, we always can write something like File.readlines('/home/shock_one/test.rb').map{ |line| line.upcase } but this way we create unneeded intermediate array which can be pretty big. There is also a method IO::foreach, but it doesn't collect return values. Besides it seems pretty logical and natural to have a block in this method.
on 2013-01-04 16:54
Issue #7654 has been updated by shock_one (Володимир Шацький). Thank you, Eregon, especially for in place methods. I should definitely pay more attention to them - functional languages made me a little suspicious of this sort of things. But I still think it would be nice to have an optional block in IO::readlines, at least for convenience. Enumerable#grep has similar behavior and I find it really cool and useful. Also this change doesn't break anything, is easy to implement and makes the code more concise. ---------------------------------------- Feature #7654: Add optional code block to IO::readlines https://bugs.ruby-lang.org/issues/7654#change-35213 Author: shock_one (Володимир Шацький) Status: Open Priority: Normal Assignee: Category: core Target version: Of course, we always can write something like File.readlines('/home/shock_one/test.rb').map{ |line| line.upcase } but this way we create unneeded intermediate array which can be pretty big. There is also a method IO::foreach, but it doesn't collect return values. Besides it seems pretty logical and natural to have a block in this method.
on 2013-01-25 04:18
Issue #7654 has been updated by ko1 (Koichi Sasada). next minor issue or 2.0.0 issue? ---------------------------------------- Feature #7654: Add optional code block to IO::readlines https://bugs.ruby-lang.org/issues/7654#change-35604 Author: shock_one (Володимир Шацький) Status: Open Priority: Normal Assignee: Category: core Target version: Of course, we always can write something like File.readlines('/home/shock_one/test.rb').map{ |line| line.upcase } but this way we create unneeded intermediate array which can be pretty big. There is also a method IO::foreach, but it doesn't collect return values. Besides it seems pretty logical and natural to have a block in this method.
on 2013-01-25 22:20
Issue #7654 has been updated by drbrain (Eric Hodel). I think next minor. It is a new feature but trunk is closed for new features. ---------------------------------------- Feature #7654: Add optional code block to IO::readlines https://bugs.ruby-lang.org/issues/7654#change-35638 Author: shock_one (Володимир Шацький) Status: Open Priority: Normal Assignee: Category: core Target version: Of course, we always can write something like File.readlines('/home/shock_one/test.rb').map{ |line| line.upcase } but this way we create unneeded intermediate array which can be pretty big. There is also a method IO::foreach, but it doesn't collect return values. Besides it seems pretty logical and natural to have a block in this method.
on 2013-01-25 22:38
Issue #7654 has been updated by drbrain (Eric Hodel). Target version set to next minor ---------------------------------------- Feature #7654: Add optional code block to IO::readlines https://bugs.ruby-lang.org/issues/7654#change-35643 Author: shock_one (Володимир Шацький) Status: Open Priority: Normal Assignee: Category: core Target version: next minor Of course, we always can write something like File.readlines('/home/shock_one/test.rb').map{ |line| line.upcase } but this way we create unneeded intermediate array which can be pretty big. There is also a method IO::foreach, but it doesn't collect return values. Besides it seems pretty logical and natural to have a block in this method.
on 2013-02-22 01:13
Issue #7654 has been updated by ko1 (Koichi Sasada). Assignee set to matz (Yukihiro Matsumoto) ---------------------------------------- Feature #7654: Add optional code block to IO::readlines https://bugs.ruby-lang.org/issues/7654#change-36742 Author: shock_one (Володимир Шацький) Status: Open Priority: Normal Assignee: matz (Yukihiro Matsumoto) Category: core Target version: next minor Of course, we always can write something like File.readlines('/home/shock_one/test.rb').map{ |line| line.upcase } but this way we create unneeded intermediate array which can be pretty big. There is also a method IO::foreach, but it doesn't collect return values. Besides it seems pretty logical and natural to have a block in this method.
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.