This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def merge(a: Stream[Int], b: Stream[Int], c: Stream[Int]): Stream[Int] = { | |
val m = a.head min b.head min c.head | |
Stream.cons(m, merge( | |
if (m < a.head) a else a.tail, | |
if (m < b.head) b else b.tail, | |
if (m < c.head) c else c.tail)) | |
} | |
def hamming: Stream[Int] = Stream.cons(1, merge( | |
hamming.map(_ * 2), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Applicative functors (Haskell - Scalaz comparison) | |
val mult = (_:Int) * (_:Int) | |
val multc = mult.curried | |
// (*) <$> Just 3 <*> Just 5 | |
some(5) <*> some(3) ∘ multc | |
// pure (*) <*> Just 3 <*> Just 5 | |
some(5) <*> (some(3) <*> multc.pure[Option]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz._ | |
object ValidationApplicative extends Application { | |
import Scalaz._ | |
case class Message(b: String) | |
// special-case sufficient for scalaz-camel | |
implicit def ExceptionSemigroup: Semigroup[Exception] = semigroup((e1, e2) => e1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz._ | |
object ValidationKleisli extends Application { | |
import Scalaz._ | |
// ------------------------------------------------------------------------------------------------ | |
// Monadic use of scalaz.Validation to sequence dependent computations | |
// e.g. processors in a route, see also Kleisli composition of processors in scalaz-camel: http://goo.gl/CUIlQ | |
// ------------------------------------------------------------------------------------------------ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz._ | |
object ValidationApplicative extends Application { | |
import Scalaz._ | |
// ----------------------------------------------------------------------------------- | |
// Applicative use of scalaz.Validation to combine results of independent computations | |
// e.g. results from multiple recipients, see also multicast EIP in scalaz-camel: http://goo.gl/FXWRi | |
// ----------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz._ | |
object ValidationPromise extends Application { | |
import scalaz.Scalaz._ | |
import scalaz.concurrent.Promise | |
import scalaz.concurrent.Strategy | |
// ------------------------------------------------ | |
// Applicative composition of concurrent functions | |
// ------------------------------------------------ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.scalatest.matchers.MustMatchers | |
import scalaz._ | |
import scalaz.camel._ | |
object RouterConfig { | |
import org.apache.camel.impl.DefaultCamelContext | |
val context = new DefaultCamelContext | |
val template = context.createProducerTemplate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Responder._ | |
import scalaz._ | |
object ResponderDemo extends Application { | |
import Scalaz._ | |
// -------------------------------------------------------------------------- | |
// Uses Responder (a continuation monad) to compose asynchronous functions. | |
// -------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz._ | |
object Example extends Application { | |
import Scalaz._ | |
import Scalaz._ | |
// | |
// monadic use of Either |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ########################################################### | |
// | |
// Demonstrates how to supervise an Akka consumer actor. | |
// | |
// The consumer consumes messages from a file endpoint: | |
// - successful message processing by the consumer will | |
// positively acknowledge the message receipt, causing | |
// the file endpoint to delete the file. | |
// - an exception during message processing will cause a | |
// supervisor to restart the consumer. Before restart, |
OlderNewer