Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8552447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:25:33+00:00 2026-06-11T14:25:33+00:00

Tony Morris gave a talk with this snippet . He’s using ReaderWriterState monad to

  • 0

Tony Morris gave a talk with this snippet.

He’s using ReaderWriterState monad to provide controlled read/write access to an implicit context. That makes sense.

How do I use the code? I would like to see an example “main” program that uses this monad.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:25:34+00:00Added an answer on June 11, 2026 at 2:25 pm

    Scalaz 7 now provides this monad, and the following is a complete working example, translated with minor revisions from the example by Michael Pilquist that’s linked in the comments above.

    package scalaz.example
    
    import scalaz._, Scalaz._
    
    
    object RWSExample extends App {
      case class Config(port: Int)
    
      def log[R, S](msg: String): ReaderWriterState[R, List[String], S, Unit] =
        ReaderWriterStateT {
          case (r, s) => (msg.format(r, s) :: Nil, (), s).point[Id]
        }
    
      def invokeService: ReaderWriterState[Config, List[String], Int, Int] =
        ReaderWriterStateT {
          case (cfg, invocationCount) => (
            List("Invoking service with port " + cfg.port),
            scala.util.Random.nextInt(100),
            invocationCount + 1).point[Id]
        }
    
      val program: RWS[Config, List[String], Int, Int] = for {
        _ <- log("Start - r: %s, s: %s")
        res <- invokeService
        _ <- log("Between - r: %s, s: %s")
        _ <- invokeService
        _ <- log("Done - r: %s, s: %s")
      } yield res
    
      val (logMessages, result, invocationCount) = program run (Config(443), 0)
      println("Result: " + result)
      println("Service invocations: " + invocationCount)
      println("Log: %n%s".format(logMessages.mkString("\t", "%n\t".format(), "")))
    }
    

    This is tested against Scalaz 7.2.18, which is easily available from Maven’s Central Repository as a Maven or SBT dependency.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was just pottering about with Tony Morris' excellent exercise on catamorphisms , when
Building on Tony's answer on this question : If I want to do something
On page 64 of LINQ To Objects Using C# 4.0 (Tony Magennis) he states
What's wrong with this: wchar_t * t = new wchar_t; t = Tony; I
I have the following JSON: {COLUMNS:[ID,FIRSTNAME],DATA:[[1,Steve],[2,Jim],[3,Bill],[4,Tony]]} I am trying to write some jQuery that
I have a string that contains a url which looks like this: http://www.test.com/images/tony 's
Tony Andrews in another question gave an example of: IF p_c_courtesies_cd || p_c_language_cd ||
How would I go about vertically centering the name Tony Robbins for this drop
I have a function with a name, like this: function tony { //do something
So, you've all probably seen Iron Man where Tony interacts with an AI system

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.