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
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions core/src/main/scala/cats/MonadState.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ package cats
* }}}
*/
trait MonadState[F[_], S] extends Monad[F] {
def apply[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!


def get: F[S]

def set(s: S): F[Unit]
Expand Down