Sitelet https://github.com/funcool/cats/pull/210
Skip to content

Re-add state monad - #210

Merged
sovelten merged 5 commits into
funcool:masterfrom
sovelten:add-state-monad
Aug 29, 2018
Merged

sovelten merged 5 commits into
funcool:masterfrom
sovelten:add-state-monad

Conversation

@sovelten

@sovelten sovelten commented Jan 21, 2018 •

Copy link
Copy Markdown
Collaborator

This PR readds the state monad implementation from the previous version of cats (https://github.com/funcool/cats/blob/1.2.1/src/cats/labs/state.cljc) with some changes. The changes were:

  • changed function names from *-state to * to avoid useless repetition
  • fixed some implementation errors that were causing the state monad to not work properly
  • added another helper function (wrap-fn)
  • added tests

Comment thread src/cats/monad/state.cljc Outdated
(return y)))
(def initial-state 1)
(run-state computation initial-state)
This should be return something to: #<Pair [1 2]>"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should return #<Pair [1 2]>

@ai212983

ai212983 commented May 1, 2018

Copy link
Copy Markdown

is there any way to upvote this? :)

@sovelten

Copy link
Copy Markdown
Collaborator Author

@niwinz Can we merge this?

@caioaao caioaao left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🥇

@sovelten
sovelten merged commit cee8358 into funcool:master Aug 29, 2018
@sovelten
sovelten deleted the add-state-monad branch August 29, 2018 21:40
@mccraigmccraig

Copy link
Copy Markdown
Contributor

this makes me a bit happy - i was using a private version of the old state-monad

i'm also using a private version of the cats.labs.monad-trans monad transformer stuff so that i can work with a promise of state (i.e. Deferred on clj and Promesa on cljs)

what dyall think of reviving the monad transformer stuff too ?

@sovelten

Copy link
Copy Markdown
Collaborator Author

I never found myself in need of using a monad transformer in Clojure, but I don't see why not revive them.

@mping

mping commented Sep 3, 2018

Copy link
Copy Markdown

Can we also update the docs to reflect the new monad? Keep up the good work guys!

sovelten pushed a commit to nubank/cats that referenced this pull request Sep 3, 2018
* Change either monad to record

This allows us to use `clojure.spec` with it :)

```clojure
(s/def :un/right int?)
(s/def :un/left string?)
(s/def :either/spec (s/and either/either?
                           (s/or :right (s/and either/right? (s/keys :req-un [:un/right]))
                                 :left (s/and either/left? (s/keys :req-un [:un/left])))))
```

I'm still not sure how to make it compatible with generators.

* Turn maybe monad into record

* Turn identity into record

* Exception monad type -> record

* Add identity predicate

* Fix issue of dynamic context overriding default context

* Fix comment indentation

* convert maybe/maybe from func to macro to delay arg eval

* cond -> boolean logic refactor

* Add test info to README

* require maybe macro in cljs; only check assertion error in clj

* Test delayed maybe/maybe arg evaluation in cljs

* change test case to pass valid argument type to 'maybe' function

* test to ensure `default` isn't evaluated when unused in `maybe`

* Fix typo on 'Pattern matching' link to cats.match

* Update dependencies.

* Set version to 2.2.0

* Rename Success/Failure value names to better match Left/Right and Just

* Re-add state monad (funcool#210)

* re-add state monad
hojacartaft added a commit to hojacartaft/cats that referenced this pull request Aug 25, 2024
When the state monad was re-added in funcool/cats#210, `*-state` functions were renamed to `*` (funcool/cats#210 (comment)) but `run-state` was not updated to `run` in a few docstrings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants