Skip to content

Instantly share code, notes, and snippets.

View channingwalton's full-sized avatar
🏠
Working from home

Channing Walton channingwalton

🏠
Working from home
View GitHub Profile
@travisbrown
travisbrown / needle-in-haystack.scala
Created November 13, 2012 22:57
Digging through arbitrarily nested case classes, tuples, and lists
/**
* Digging through arbitrarily nested case classes, tuples, and lists
* by Travis Brown
*
* In response to this question by Channing Walton on the Shapeless dev list:
*
* https://groups.google.com/d/msg/shapeless-dev/hn7_U21tupI/Zm9h3uNb51gJ
*
* Tested with Scala 2.9.2 and Shapeless 1.2.3. Should work on 1.2.2 with minor edits.
*/
@etorreborre
etorreborre / gist:3870064
Created October 11, 2012 03:54
Unboxed union types with a context bound
/**
* this is an experiment to create unboxed union types with a phantom type and a context bound.
* All the good ideas come from @milessabin post, comments and links: http://www.chuusai.com/2011/06/09/scala-union-types-curry-howard/#comment-22
*/
/** trait for anything that can be A or B */
trait Or[A, B] {
// a phantom type, there will be no instance of this type that we'll use
type l[T]
// an alias for l[t]
@puffnfresh
puffnfresh / WriterTExample.scala
Created August 14, 2012 01:57
Example of scalaz' WriterT for Atlassian (pure functional logging)
import scalaz.WriterT
import scalaz.NonEmptyList
import scalaz.syntax.id._
import scalaz.std.option._
import scalaz.syntax.std.option._
type OptionLogger[A] = WriterT[Option, NonEmptyList[String], A]
val two: OptionLogger[Int] = WriterT.put(2.some)("The number two".wrapNel)
@larsrh
larsrh / gist:3240574
Created August 2, 2012 20:54 — forked from channingwalton/gist:3230464
Example of Kleisli composition of Either
object KleisliValidation extends App {
import scalaz._
import Scalaz._
import scala.util.control.Exception._
type EEither[+T] = Either[String, T]
def toDouble(s: String): EEither[Double] = allCatch.either(s.toDouble).fold(_.toString.left, _.right)
def sqrt(d: Double): EEither[Double] = if (d >= 0) math.sqrt(d).right else "sqrt(%s) is too complex for me".format(d).left
@krasserm
krasserm / MonadTransformerExamples.scala
Created July 14, 2011 10:32
Scalaz 7 monad transformer examples
import scalaz._
import Scalaz._
object MonadTransformerExamples {
def main(args: Array[String]) = run
def run {
// ------------------------------------------------------
// Combined Option/Option
// ------------------------------------------------------