Scalaz State Monad

Michael Pilquist · 20K views · 2012 · 2:03:51

Open on YouTube

Functional programmingProgramming language designtalk

Why Stack Overflow recommends it

Stack Overflow users link it as the go-to walkthrough of the Scalaz State monad when answering questions about learning Scalaz and about State itself.

Recommended by 4 people across 4 different months, 2011 to 2016.

What it is

A two-hour talk by Michael Pilquist introducing the State monad from Scalaz 7, built up through step-by-step Scala examples. Source code and slides are published alongside it, and it follows an earlier unrecorded Scalaz 7 introduction.

What people said

Strong rec huynhjl · 2011-10 · Stack Overflow · on “Scalaz state monad examples”

I haven't seen many examples of the scalaz state monad. There is this example [LINK] but it is hard to understand and there is only one other question [LINK] on stack overflow it seems. I'm going to post a few examples I've played with but I would welcome additional ones. Also if somebody can provide example on why init , modify , put and gets are used for that would be great. Edit: here [this video] is an awesome 2 hours presentation on the state monad.

Strong rec Łukasz · 2016-01 · Stack Overflow · on “Encapsulate series of steps within a Monad”

Perhaps when you get deeper understanding of some common monads, the general concept will become clearer. You could read about `Option`, `Try`, `Either`, `Future`. Maybe something from scalaz, there is a great presentation on `State` monad here [this video]

Recommends ron · 2012-09 · Stack Overflow · on “Finding my way through Scalaz”

Some of the videos I found useful: Scalaz overview by Nick Partridge [LINK] and by Jason Zaugg [LINK] Practical Scalaz by Chris Marshall [LINK] Lenses by Edward Kmett [LINK] (5 parts) Reader monad by Tony Morris [LINK] and by Rúnar Bjarnason [LINK] State monad by Michael Pilquist [this video] Monad transformers by Jordan West [LINK] Most of these have great slides, if you are hardcore then read them without the video. Also learn [LINK] to read Haskell [LINK] type signatures and browse the Haskell typeclassopedia [LINK] .

Recommends ron · 2012-09 · Stack Overflow · on “Good scalaz introduction”

Videos: Scalaz overview by Nick Partridge [LINK] and by Jason Zaugg [LINK] Practical Scalaz by Chris Marshall [LINK] Lenses by Edward Kmett [LINK] (5 parts) Reader monad by Tony Morris [LINK] and by Rúnar Bjarnason [LINK] State monad by Michael Pilquist [this video] Monad transformers by Jordan West [LINK] (Copied from my answer of a closed duplicate).

Recommends Pengin · 2013-10 · Stack Overflow · on “Scala state monad in for comprehension”

I'm studying Michael Pilquist's excellent state monad lecture here [this video] . I get stuck at 54 min with two questions. If ofs is an Option[FollowerStats] , what is the ? operator? I can't find a ternary operator on Option in Scala 2.10.2 How does the last generator put an updated cache (with hit or miss incremented) back into the State result of the checkCache method? The returned State seems to be be discarded and the for comprehension seems to only yielding the Option[FollowerStats] . def checkCache(u: String): State[Cache, Option[FollowerState]] = for { c <- State.get[Cache] ofs <- State.state { c.get(u).collect { case Timestamped(fs, ts) if !state(ts) => fs } } _ <- State.put(ofs ? c.rec

Cites windweller · 2014-01 · Stack Overflow · on “Scala lambda expression”

(It seems like I ask too many basic questions, but Scala is very difficult, especially when it comes to the language feature or syntactic sugar, and I come from a Java background..) I am watching this video: Scalaz State Monad on YouTube. The lecturer wrote these code: trait State[S, +A] { def run(initial: S):(S, A) def map[B](f: A=>B): State[S, B] = State { s => val (s1, a) = run(s) (s1, f(a)) } He said the State on the forth line is a "lambda" expression (I may have misheard). I'm a bit confused about this. He did have an object State , which looks like this: Object State { def apply[S, A](f: S=>(S, A)): State[S, A] = new State[S, A] { def run(i: S) = f(i) } } The lecturer said he was invo

Cites Sonia Hamilton · 2015-03 · Stack Overflow · on “Scala case class with function parameters”

Thanks very much @dk14. It's late here so I'll grok this properly tomorrow and vote. Interestingly I'm watching Scalaz State Monad [this video] which shows this exact situation. Paraphrasing the presenter at 18:40, the syntax is a "lambda that takes an S and returns an SB, lifted into State".