-
Notifications
You must be signed in to change notification settings - Fork 12
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
Compiler: allow function calls on lazy state #835
Conversation
@josephjclark I want to add a good runtime/cli test for this. where do you think would be best to add that. fn((state) => {
state.callMeMaybe = (value) => {
state.greetings = `hello ${value}`
return state; // crazy! seems every function body that does something with state has to return it
}
return state
});
fn(state => {
state.name = "John"
return state;
})
fn($.callMeMaybe($.name)) // note: if callMeMaybe doesn't return state, next operation wouldn't have state passed. Then the value at NoteWe can say that. every function body that has something to do with state should return it. |
Note: I ignored the other example from #684 fn((state) => {
$.callMeMaybe()
}) Because according to our discussion. that should be ILLEGAL! |
Uh, well not really. It depends on how it's used. We talk about Operations - a function which takes state and returns state. If you're using a function as an operation - then yeah, the function body must return state. But I can re-write your code like this:
But I think you're hitting on something important. Since we can't use lazy state inside a callback, the use of this is limited. If I do:
Then the function must indeed be an Operation. We can do stuff like this though
But thinking this through is making me really de-value the utility of functions on state. I think it's just creating confusion. #648 would be a much more useful facility (although the issue needs a lot of love!) |
@doc-han let me think about this but this does feel low priority now 🤔 If it feels safe I'll merge it |
Hiya @doc-han - I want to merge this even though I don't think it's very valuable in the end. We have a suite of tests in Can I ask you to create a file called Don't go too overboard - just plug in a nice starting point :) Thanks! |
Done |
Thanks @doc-han ! Appreciate it |
290ecb9
to
17d32e2
Compare
Short Description
Currently function calls on lazy-state do not work.
eg.
This is because, we fail to wrap the state callback well. This update fixes that.
How it worked before and after
Given the source code
fn($.callMeMaybe())
fn((state => state.callMeMaybe)())
fn(state => state.callMeMaybe())
Fixes #684
Implementation Details
Steps
QA Notes
List any considerations/cases/advice for testing/QA here.
AI Usage
Please disclose how you've used AI in this work (it's cool, we just want to know!):
You can read more details in our Responsible AI Policy