-
Notifications
You must be signed in to change notification settings - Fork 15
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
add flow/for macro #142
add flow/for macro #142
Conversation
deeb953
to
16ea6ef
Compare
I don't think I would be a user of this macro, but I understand if people want to use it. I do think this is general enough to be part of https://github.com/nubank/cats/blob/master/src/cats/core.cljc though. It works for any monad, so it is kind of syntactic sugar for |
I'm happy to submit a separate PR for cats, but I also like the idea of having this in state-flow so it's obvious to state-flow users. |
I agree, but I think that |
|
@@ -38,3 +40,22 @@ | |||
|
|||
(import-fn state-flow.state/gets get-state) | |||
(import-fn state-flow.state/modify swap-state) | |||
|
|||
(defmacro for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be implemented here or in another namespace, such as in state-flow.state
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not really a state
fn, but it's not really core
for state-flow either. We could add a new namespace like state-flow.monad
, but that might be confusing/distracting. Other ideas?
What about state-flow.compose
? That might encourage thinking about some other ideas for composing flows.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I vote for state-flow.compose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the state
is actually a state monad
so there should be the place IMO, it is in the same spirit of fmap
. Not that I have a strong opinion about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case you want to use this helper in core.clj, core.clj depends on the state.clj, but it should not depend on state-flow.api, the hierarchy looks like this:
state
|
core
|
api
things that are more fundamental than core go in the state
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The struggle I'm having is that e.g. swap-state
is clearly about state
, whereas for
is about composing flows. I've already merged this but we can always move it somewhere else later and reference it from api
as we do with all the other functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
whereas
for
is about composing flows.
And composing flows seems more fundamental than even state
to me :)
not very long ago I struggled when migrating a test because there was nothing out-of-the-box like this in state-flow, and using cats like the documentation suggested felt a bit wrong, so +1. I think this is also in line with the idea that you don't have to know about the state monad to use state-flow |
Problem: apply the same flow to different sets of inputs
Some existing solutions:
Proposal
This PR adds a
state-flow.api/for
macro that works just likeclojure.core/for
, but returns a flow which wraps a sequence of flows, e.g.TODO: