top | item 22997330

(no title)

traderjane | 5 years ago

> A stateful function with effects. Your language just doesn’t have a primitive to express it.

I wonder what about generator functions?

discuss

order

dcre|5 years ago

I don't see how generators would change anything here. "with effects", "stateful", and the integration between the two are all equally important in the statement.

orange8|5 years ago

There are two different concepts as I see it, please correct me if your definitions differ.

"stateful": A function that has state, i.e. can store data

"with effects": A function that modifies data outside its own scope

Normal JS functions (as opposed to arrow function) already do this:

function foo(){};

foo.state = bar;

Generator functions take it a step further, where the function remembers internal state between calls.

williamdclt|5 years ago

Well generators are a good primitive to represent "stateful" "functions" "with effects". The concept of hooks, which somehow give the control back to React to do something, map marvelously to react.

I'd be surprised if generators didn't come into React at one point or another

traderjane|5 years ago

What are generators for you?