Skip to content

Instantly share code, notes, and snippets.

Avatar

Martin Krasser krasserm

View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am krasserm on github.
  • I am krasserm (https://keybase.io/krasserm) on keybase.
  • I have a public key whose fingerprint is B785 7B59 B25E 2385 5450 DE4C F23C A996 D0CF F605

To claim this, I am signing this object:

View Hamming.scala
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),
View Applicative functors
// 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])
View ValidationApplicative.scala
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)
View ValidationKleisli.scala
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
// ------------------------------------------------------------------------------------------------
View ValidationApplicative.scala
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
// -----------------------------------------------------------------------------------
View ValidationPromise.scala
import scalaz._
object ValidationPromise extends Application {
import scalaz.Scalaz._
import scalaz.concurrent.Promise
import scalaz.concurrent.Strategy
// ------------------------------------------------
// Applicative composition of concurrent functions
// ------------------------------------------------
View RecipientList.scala
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
View ResponderDemo.scala
import Responder._
import scalaz._
object ResponderDemo extends Application {
import Scalaz._
// --------------------------------------------------------------------------
// Uses Responder (a continuation monad) to compose asynchronous functions.
// --------------------------------------------------------------------------
View Misc.scala
import scalaz._
object Example extends Application {
import Scalaz._
import Scalaz._
//
// monadic use of Either