-
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 walkthrough file #65
Conversation
@@ -0,0 +1,262 @@ | |||
(require '[state-flow.core :refer [flow run]] |
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.
This is in a .repl file instead of .clj because the intent is to evaluate expressions one at a time, not load up a namespace.
;; primitives. Here's another primitive, which returns a specified | ||
;; value without modifying the internal state: | ||
|
||
(run (state/return {:count 37}) {:count 0}) |
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.
e3d63d7
to
44fcf76
Compare
(state/wrap-fn #(fetch-users db)) | ||
#{{:name "Philip"}})) ;; <- different spelling | ||
{:db (atom {:users #{}})}) | ||
;; => #<Pair [#{{:name "Phillip"}} {:db #atom[{:users #{{:name "Phillip"}}} 0x4c2a27a6]}]> |
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 added #66 to sugest that we include the failure information below in the return value above
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 like it and learned a bit about :mfn
and such, which I had sorta ignored until now :)
One thing I wonder about is we have a few docs kicking around with examples of how to interact with state-flow (I think I wrote two different ones). Do you think this one could replace those?
doc/walkthrough.repl
Outdated
;; | ||
;; - A monad is a wrapper around a function. | ||
;; - A state monad is a monad whose function is a function of | ||
;; some mutable state, which is managed for you by a runner. |
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.
maybe is a monad whose function is one over some mutable state
? The double occurrence of function
is tripping me up a little
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.
Updated using of
(but removing the redundancy).
;; - :state-context is a reference to mutable state, which will be | ||
;; managed by state-flow. | ||
;; | ||
;; The :mfn of a state monad is a function of state, which returns |
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.
for some reason I want to see function over state
, though I dunno if that is at all more standard, let alone correct
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 think this is subjective (incorrect to call it incorrect or non-standard). That said, I think of closures as closing over
bindings and functions being of
their arguments. Does that make sense to you?
|
||
(state/get) | ||
;; => #cats.monad.state.State{:mfn #object[...], | ||
;; :state-context #<State-E>} |
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 wonder if there is a better way to represent the state context for printing. LikeState-E
is quiet cryptic
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.
Agreed. Looking into 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.
That's on us:
state-flow/src/state_flow/state.clj
Lines 55 to 57 in 210798c
p/Printable | |
(-repr [_] | |
"#<State-E>"))) |
Without that, we get this:
(state/get)
;; => {:mfn #function[state-flow.state/reify--15501/fn--15509],
;; :state-context #object[state_flow.state$reify__15501 0x68fabfd8 "state_flow.state$reify__15501@68fabfd8"]}
That might be a better option for now. WDYT?
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.
/cc @sovelten - got an opinion on this from afar?
doc/walkthrough.repl
Outdated
;; ------------------------------------------- | ||
|
||
;; state-flow is implemented using a state monad. If you're already | ||
;; familiar with monads, great! If not, don't worrry. We'll explain |
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.
worrry
-> worry
Links? I think this replaces the introductory material, but we still need more advanced material, which might make sense to be where you have examples already with a reference to the walkthrough. |
44fcf76
to
204b25d
Compare
204b25d
to
9fe96ed
Compare
Our language about the state monad thus far has been "pay no attention the man behind the curtain", but I think it's actually helpful to explain the mechanics. I've found it especially confusing that we've adopted the term "flow" to talk about individual steps.
This PR includes a walkthrough that introduces the basic mechanics of the state monad and builds on that.