Imagine, that there are M large text files each with N lines, that are indexed from 1 to M*N. My goal is to get either all lines after the index X or just last 10 of them if X isn't provided. I could do an external if
to split these two formulas, but I want to put ? :
deep inside such as:
Dir.glob("logs/*").reverse.lazy.flat_map{ |f|
File.readlines(f).reverse.map{ |str| str.split(" ", 2) }
}.take_while.with_index{ |(i, str), n|
x ? (i.to_i >= x) : (n < 10)
}.to_a.reverse
But I get:
ArgumentError - tried to call lazy take_while without a block:`
while according to answers such as: Grouping consecutive numbers in an array
chaining .take_while.with_index
should be possible.
Do I do something wrong and don't see the bug or does .lazy
really just lack some functionality and I have to wait for some patch in future?