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.Scalaz._ | |
trait Future[A] | |
object Future { | |
def async[A](a: A): Future[A] = error("todo") | |
} | |
sealed trait NotServed |
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
/** Semigroup Action */ | |
trait SAct[A, -B] { outer => | |
def append(a: A, b: => B): A | |
def xappend(b: B, a: => A): A = append(a, b) | |
} | |
trait SActs { | |
implicit def s2sact[A](implicit semigroup: Semigroup[A]): SAct[A, A] = new SAct[A, A] { | |
override def append(a1: A, a2: => A): A = semigroup.append(a1, a2) | |
} |
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
implicit def BindSemigroup[M[_], A](implicit bind: Bind[M], s: Semigroup[A]): Semigroup[M[A]] = new Semigroup[M[A]] { | |
def append(v1: M[A], v2: => M[A]): M[A] = bind.bind(v1)((a: A) => v2.map(s.append(a, _))) | |
} |
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
// first, the Strategy pattern, in Java: | |
interface AdditionStrategy { | |
public int add(int a1, int a2); | |
} | |
// A simple polymorphic version - abstract over the type being added | |
interface PolyAdditionStrategy<A> { | |
public A add(A a1, A a2); | |
} |
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
scala> import scalaz._ | |
import scalaz._ | |
scala> import scalaz.std.list._ | |
import scalaz.std.list._ | |
scala> import scalaz.std.tuple._ | |
import scalaz.std.tuple._ | |
scala> import scalaz.syntax.bitraverse._ |
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 Monad[M[_]] { | |
def pure[A](a: A): M[A] | |
def flatMap[A, B](f: A => M[B]): M[A] => M[B] | |
def map[A, B](f: A => B): M[A] => M[B] = flatMap(a => pure(f(a))) | |
} | |
object Id { | |
type Id[X] = X | |
implicit val M: Monad[Id] = sys.error("todo") |
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.annotation.tailrec | |
sealed abstract class A { | |
def i: Int | |
} | |
object A { | |
@inline final def tpIdx(a: A) = a match { | |
case SA(_) => 0 | |
case BA(_) => 1 |
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 test | |
import collection.mutable.ListBuffer | |
/** | |
* @author Matt Hicks <[email protected]> | |
*/ | |
trait Element | |
trait Parentable extends Element { |
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 A { | |
// define an algebra over the known space of subtypes | |
def fold[X](af: A => X, bf: B => X, cf: C => X): X | |
} | |
trait B extends A { | |
def fold[X](af: A => X, bf: B => X, cf: C => X): X = bf(this) | |
} |
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 Functorial[F[_], B] { | |
def map[A](m: F[A])(f: A => B): F[B] | |
} | |
trait Monadic[M[_], B] extends Functorial[F, B] { | |
def point(b: B): M[B] | |
def flatMap[A](m: M[A])(f: A => M[B]): M[B] | |
} | |
trait Traversial[F[_], B] { |