This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
sealed trait A { | |
type X | |
case class B(x: X) | |
def b: B | |
} | |
case class J(x: String) extends A { | |
type X = String | |
override def b = B(x) |
This file contains hidden or 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
--langdef=scala | |
--langmap=scala:.scala | |
--regex-scala=/^.*case object[ \t]+([a-zA-Z0-9_]+)/\1/o,case objects/ | |
--regex-scala=/^.*object[ \t]+([a-zA-Z0-9_]+)/\1/o,objects/ | |
--regex-scala=/^.*case class[ \t]+([a-zA-Z0-9_]+)/\1/c,case classes/ | |
--regex-scala=/^.*class[ \t]+([a-zA-Z0-9_]+)/\1/c,classes/ | |
--regex-scala=/^.*trait[ \t]+([a-zA-Z0-9_]+)/\1/t,traits/ | |
--regex-scala=/^.*type[ \t]+([a-zA-Z0-9_]+)/\1/T,types/ | |
--regex-scala=/^.*def[ \t]+([a-zA-Z0-9_\?]+)/\1/m,methods/ | |
--regex-scala=/^.*val[ \t]+([a-zA-Z0-9_]+)/\1/C,constants/ |