Hey there! Just saw this now.
We can iterate through objects in many ways. The demonstration was showing that we can also iterate through objects in particular ways, as per our own use case.
We might want to create an iterator that only spits out object properties that are numbers or fall under some filter.
We could create an array of all properties and then filter, but this is creating 2 arrays whereas a generator allows us to create 0 arrays. We simply iterate over the returned iterable and deal with it as necessary
Sounds good.
If you want one or two more, Dr. Axel Rauschmayer provides some use cases with async code
Awesome ... thanks for the additional references!
@emnudge regarding your examples:
Could you explain / demonstrate 4. ?
I'm also not sure if I understand 3.
Why not use object.values().includes() ?
Hey there! Just saw this now.
We can iterate through objects in many ways. The demonstration was showing that we can also iterate through objects in particular ways, as per our own use case.
We might want to create an iterator that only spits out object properties that are numbers or fall under some filter.
We could create an array of all properties and then filter, but this is creating 2 arrays whereas a generator allows us to create 0 arrays. We simply iterate over the returned iterable and deal with it as necessary
I love the idea of using a generator for this. I might have to try an alternate!