Comments (4)
Sounds good! I'd just change the naming to value
, key
and iterable
/iteratee
, to cover each of three big iteratees in JavaScript (Array#forEach
, Map#forEach
and Set#forEach
). This will cover custom iterables, as well.
from code-block-writer.
I like this (and the other issue you opened), thanks!
It could probably be similar to the signature of Array.prototype.forEach. So currentValue[, index[, array]
.
from code-block-writer.
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 iterate
and forEach
have exactly the same amount of characters. 😂
from code-block-writer.
Hmmm... good point. The only alternative I can think of is adding a .withEach
or something like it:
writer
.writeLine(`return [`)
.withEach(indexes, index => writer.indent().writeLine(`this.array[${index}],`))
.writeLine(`]`)
from code-block-writer.
Related Issues (20)
- Ability to write with a hanging indent HOT 1
- Error when running `yarn test` HOT 1
- Performance: Move regex to be static
- Add ability to specify max line length HOT 1
- Add closeComment()
- Add `indent(times)`
- Improve Performance HOT 1
- isLastBlankLine() and getLength() should not call toString() HOT 1
- Add method for iterating over the previously written characters
- Should not push empty strings onto internal array
- Add insert method HOT 2
- Rename `withHangingIndentation` to `hangingIndent` HOT 1
- Stays in string even after newline?
- Release for Deno HOT 1
- Declaration and capturing of variables HOT 1
- getBaseTypes() and getBaseClass() not working HOT 2
- Property generic types
- TypeScript error TS2351: This expression is not constructable. HOT 11
- TypeError: CodeBlockWriter is not a constructor HOT 2
- Suggestion: writer.pairedWrite(startToken, endToken, newLine, indent, block: () => void)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from code-block-writer.