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._ | |
import Scalaz._ | |
import scalaz.effects._ | |
import java.io._ | |
/** | |
* Background reading: | |
* http://www.stackmob.com/2011/12/scalaz-post-part-2/ | |
* http://blog.sigfpe.com/2007/11/io-monad-for-people-who-simply-dont.html |
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
object Generics { | |
import shapeless.HList | |
import shapeless.Nat | |
import shapeless.Nat._ | |
import shapeless._ | |
trait <[A <: Nat, B <: Nat] | |
implicit def lt1[B <: Nat] = new <[_0, Succ[B]] {} | |
implicit def lt2[A <: Nat, B <: Nat](implicit lt: A < B) = new <[Succ[A], Succ[B]] {} |
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 scala.xml.NodeSeq | |
object RenderExample { | |
object Model { | |
trait Toy | |
case class Bike extends Toy | |
case class Train extends Toy |
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._ | |
import Scalaz._ | |
/** | |
* Use the state monad to 'process a trade' and store the new trade. | |
* As well as processing the trade, handle validation errors. | |
*/ | |
object StateMonad extends App { | |
case class Trade(info: String) |
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
object KleisliValidation extends App { | |
import scalaz._ | |
import Scalaz._ | |
import scala.util.control.Exception._ | |
type EValidation[+T] = Validation[String, T] | |
implicit val binding = new Bind[EValidation] { | |
def map[A, B](fa: EValidation[A])(f: A => B): EValidation[B] = fa.map(f) | |
def bind[A, B](fa: EValidation[A])(f: A => EValidation[B]): EValidation[B] = fa.flatMap(f) | |
} |
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
object KleisliValidation extends App { | |
import scalaz._ | |
import Scalaz._ | |
import scala.util.control.Exception._ | |
implicit def vm = Validation.validationMonad[String] | |
type EValidation[+T] = Validation[String, T] | |
def toDouble(s: String): EValidation[Double] = allCatch.either(s.toDouble).fold(_.toString.fail, _.success) |
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
@channingwalton Recently read »I, Robot« from Asimov. The short stories are entertaining and very thoughtful. | |
@channingwalton I would like a wizard where I tell it I like Asimov (especially Daneel and Giskard) and Clarke, and it recommends others. | |
@channingwalton pretty much anything by Alastair Reynolds. House of Suns is particularly great. | |
@channingwalton I’ve enjoyed the Laundry novels by Charles Stross. | |
@channingwalton "Wool" series by Hugh Howey. |
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
// Inspired by http://dave.fayr.am/posts/2012-10-4-finding-fizzbuzz.html | |
object FizzBuzz extends App { | |
import scalaz._ | |
import Scalaz._ | |
def fizzbuzz(i: Int) = ((i % 3 == 0) option "fizz") |+| ((i % 5 == 0) option "buzz") | i.shows | |
for (i <- 1 to 100) {println(i + " " + fizzbuzz(i))} | |
} |
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
package stereotypes | |
import shapeless._ | |
import Searchable._ | |
object FunctionThisUp { | |
// pretend we have some case classes - they needn't be ours of course | |
case class Name(name: String) | |
case class Description(description: String) |
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
trait FooComponent { | |
def bar: BarComponent#Bar | |
case class Foo(foofy: String) | |
} | |
trait BarComponent { | |
def foo: FooComponent#Foo |
OlderNewer