Scalaz state monad examples

I assume, scalaz 7.0.x and the following imports (look at answer history for scalaz 6.x): import scalaz._ import Scalaz._ The state type is defined as State[S, A] where S is type of the state and A is the type of the value being decorated. The basic syntax to create a state value makes use of … Read more

Doing HTTP request in Scala

I use the following: https://github.com/scalaj/scalaj-http. Here’s a simple GET request: import scalaj.http.{Http, HttpOptions} Http(“http://example.com/search”).param(“q”, “monkeys”).asString and an example of a POST: val result = Http(“http://example.com/url”).postData(“””{“id”:”12″,”json”:”data”}”””) .header(“Content-Type”, “application/json”) .header(“Charset”, “UTF-8”) .option(HttpOptions.readTimeout(10000)).asString Scalaj HTTP is available through SBT: libraryDependencies += “org.scalaj” % “scalaj-http_2.11” % “2.3.0”

How do I replace a program written as a sequenced stream of state transitions with scalaz-stream?

import io.FilePath import scalaz.stream._ import Process._ import scalaz.concurrent.Task import Task._ import scalaz.{Show, Reducer, Monoid} import scalaz.std.list._ import scalaz.syntax.foldable._ import scalaz.syntax.bind._ import scalaz.stream._ import io._ import scalaz.stream.text._ import Processes._ import process1.lift import control.Functions._ /** * A Fold[T] can be used to pass over a Process[Task, T]. * * It has: * * – accumulation, with an … Read more

Avoiding memory leaks with Scalaz 7 zipWithIndex/group enumeratees

This will come as little consolation for anyone who’s stuck with the older iteratee API, but I recently verified that an equivalent test passes against the scalaz-stream API. This is a newer stream processing API that is intended to replace iteratee. For completeness, here’s the test code: // create a stream containing `n` arrays with … Read more

Good scalaz introduction [closed]

Hieko Seeberger has recently started blogging on functional programming and category theory applied to Scala. Two opening posts are very educative (and easy to read), and can help getting over the initial barrier in learning scalaz. EDIT: When you get comfortable with the fundamentals, I would recommend you to read through http://apocalisp.wordpress.com/ (blog driven by … Read more