Skip to content
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 state method to MonadState #1651

Merged
merged 5 commits into from
May 10, 2017
Merged

Add state method to MonadState #1651

merged 5 commits into from
May 10, 2017

Conversation

oskoi
Copy link
Contributor

@oskoi oskoi commented May 6, 2017

No description provided.

Copy link
Contributor

@edmundnoble edmundnoble left a comment

Choose a reason for hiding this comment

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

a) apply on a trait is a recipe for name collisions. Call it state maybe, to be consistent with reader on MonadReader?
b) It's not consistent to have this on MonadState and have no method from Either on MonadError.

@oskoi
Copy link
Contributor Author

oskoi commented May 7, 2017

@edmundnoble
a) You're right. Changed the name of method.
b) Sorry, but I did not understand you. We have method raiseError in MonadError. Explain, please, what did you mean

@oskoi oskoi changed the title Add apply method to MonadState Add state method to MonadState May 7, 2017
@edmundnoble
Copy link
Contributor

To clarify and correct myself, in ApplicativeError, a method def either[A](x: E Either A): F[A], which just calls _.fold(raiseError, pure).

@oskoi
Copy link
Contributor Author

oskoi commented May 7, 2017

@edmundnoble done.

Copy link
Contributor

@edmundnoble edmundnoble left a comment

Choose a reason for hiding this comment

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

LGTM.

@@ -17,6 +17,9 @@ package cats
* }}}
*/
trait MonadState[F[_], S] extends Monad[F] {
def state[A](f: S => (S, A)): F[A] =
flatMap(get)(s => f(s) match { case (s, a) => inspect(_ => a)})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this use set to set the S resulting from f(s)? As is this will just return the initial S, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@peterneyens Right. Forgot to update the state ( Fixed this!

@kailuowang
Copy link
Contributor

We might want to add some doctests.

@oskoi
Copy link
Contributor Author

oskoi commented May 8, 2017

@kailuowang done

Copy link
Contributor

@kailuowang kailuowang left a comment

Choose a reason for hiding this comment

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

LGTM

@edmundnoble edmundnoble merged commit 8c38980 into typelevel:master May 10, 2017
@kailuowang kailuowang modified the milestone: 1.0.0-MF May 18, 2017
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.

4 participants