New issue
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
Iterative writes #16
Comments
I like this (and the other issue you opened), thanks! It could probably be similar to the signature of Array.prototype.forEach. So |
Sounds good! I'd just change the naming to |
I looked around a bit in my code to see where I could apply this and there are only a few exceptions to the rule I've found: I always indent the block where I iterate. The example I've given is not how you'd probably do it in a real project... Instead, it would be const indexes = [5, 9, 10, 15, 17]
writer
.writeLine(`return [`)
.indentBlock(() => {
writer.iterateWriteLine(indexes, index => `this.array[${index}],`)
})
.writeLine(`]`) The chain is broken anyway and for such a short line you'd pretty much inline it anyway: const indexes = [5, 9, 10, 15, 17]
writer
.writeLine(`return [`)
.indentBlock(() => {
indexes.forEach(index => writer.writeLine(`this.array[${index}],`)
})
.writeLine(`]`) 🤔 PS. It's funny how |
Hmmm... good point. The only alternative I can think of is adding a writer
.writeLine(`return [`)
.withEach(indexes, index => writer.indent().writeLine(`this.array[${index}],`))
.writeLine(`]`) |
Similarly to the reason
conditionalWrite
was introducted, it would be really nice if we were not forced to break the chain and introduce afor-of
loop with a singlewriteLine
call.Something along the lines of the following would be great.
The text was updated successfully, but these errors were encountered: