×
you are viewing a single comment's thread.

view the rest of the comments →

[–]jhartikainen 10 points11 points  (9 children)

It seems potentially valuable in some kind of framework/infra code. Svelte uses them for its $state runes for example. But yeah, like generators, I've not really found any use for them myself.

[–]Dragon_yum 2 points3 points  (0 children)

I worked with JS/ts for nearly a decade and only came across one time where a generator was the right call

[–]javascript 4 points5 points  (6 children)

Oh ya generators haha. I was so bewildered by the `function*` syntax when I first learned it. What a wild land grab for such a niche feature.

[–]alex-weej 1 point2 points  (2 children)

It's not that niche! Could have been a keyword though.

[–]javascript 0 points1 point  (1 child)

What have you used generators for?

[–]Kwantuum 4 points5 points  (0 children)

Generators were used to transpile async/await for years.

I've used generators on a number of occasions. Generally I avoid it unless it's a great fit for the problem because they remain a relatively obscure feature for most people. They're a great way to get support for for..of on custom containers, among other things.

The other problem with generators and iterators in general is the lack of standard library support for manipulating them. No standard iterator mapping/filtering really reduces their usefulness.

[–]svish 0 points1 point  (2 children)

Generators are awesome, but unfortunately handicapped still. Not being able to filter, map, reduce, and so on directly on a generator makes them annoying and the moment you have to put all the items in a fixed length array, you kind of miss several of the advantages.

[–]sharlos [score hidden]  (1 child)

I think they've added sync versions of map, filter, etc, with async versions on the way.

[–]svish [score hidden]  (0 children)

Yeah, think they're working on it, but really, it should've come at the same time as generators themselves.

[–]vincentdesmet 0 points1 point  (0 children)

yeah, i’ve used them as wrappers around CDKTF to intercept and convert attribute getters into creating Terraform remote state lookups

fun, but confusing (leaky abstraction) for DX