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
//Either based on the existence of a typeclass. | |
sealed trait Exists[TC[_], N, Y]{ | |
def apply(no: N, yes: Y): Either[N, Y] | |
} | |
object Exists extends LowPriorityExists{ | |
def apply[TC[_]] = new{ | |
def apply[N, Y](n: N, y: Y)(implicit exists: Exists[TC, N, Y]) = exists(n, y) | |
} | |
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 ComposeBuilder[F, G] extends DepFn2[F, G] | |
object ComposeBuilder extends LowPriorityComposeBuilder{ | |
implicit def cc[C1 <: Poly, L1 <: HList, C2 <: Poly, L2 <: HList] | |
(implicit unpack1: Unpack1[C1, Compose1, L1], | |
unpack2: Unpack1[C2, Compose1, L2], | |
pre: hl.Prepend[L1, L2]): Aux[C1, C2, Compose1[pre.Out]] = | |
new ComposeBuilder[C1, C2]{ | |
type Out = Compose1[pre.Out] | |
def apply(c1: C1, c2: C2) = new Compose1[pre.Out] |
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 twotails.mutualrec | |
class Dog{ | |
@mutualrec final def dog1(count: Int): Int = if (count == 0) count else dog2(count - 1) | |
@mutualrec final def dog2(count: Int): Int = if (count == 0) count else if (count % 2 == 0) dog1(count - 1) else dog3(count - 1) | |
@mutualrec final def dog3(count: Int): Int = if (count == 0) count else dog1(count - 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
trait LowPriorityOneOf2{ | |
type Aux[O, I, B <: Bool] = OneOfProof[O, I]{ type Value = B } | |
implicit def diverge[O, I](implicit truth: Aux[O, I, True]): Aux[O, I, False] = ??? | |
implicit def not[O, I]: Aux[O, I, False] = new OneOfProof[O, I]{ | |
type Value = False | |
} | |
} |
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
class ContainsProof[Items]{ | |
def apply[Obj](obj: Obj)(implicit yes: Contains[Obj, Items]) = true | |
} | |
class ExcludesProof[Items]{ | |
def apply[Obj](obj: Obj)(implicit no: Excludes[Obj, Items]) = false | |
} | |
scala> val yesItDoes = new ContainsProof[Int | Double] | |
scala> yesItDoes(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
type |[A, B] = (A, B) | |
trait OneOfProof[Obj, Items]{ | |
type Value <: Bool | |
} | |
object OneOfProof extends LowPriorityOneOf{ | |
def apply[Obj, Items](implicit oneOf: OneOfProof[Obj, Items]): Aux[Obj, Items, oneOf.Value] = oneOf | |
implicit def left[L, R, Obj <: L]: Aux[Obj, L | R, True] = new OneOfProof[Obj, L | R]{ |
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
sealed trait Bool | |
sealed trait True | |
sealed trait False | |
trait OneOfProof[Obj, Items]{ | |
type Value <: Bool | |
} | |
object OneOfProof{ | |
type Aux[O, I, B <: Bool] = OneOfProof[O, I]{ type Value = 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
trait Unapply2[TC[_[_]], MA, MB] extends Serializable { | |
type M[_] | |
type A | |
type B | |
def TC: TC[M] | |
def substA: MA => M[A] | |
def substB: MB => M[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
trait Merge[LSet, RSet]{ | |
type Out | |
} | |
object Merge extends LowPriorityMerge{ | |
implicit def tset1[T, S](implicit m: Merge[T, S]): Aux[TSet[T], S, m.Out] = | |
new Merge[TSet[T], S]{ type Out = m.Out } | |
implicit def tset[L, R, O, S](implicit ev: Aux[TSet[R], S, O], m: Merge[L, O]): Aux[TSet[L|R], S, m.Out] = | |
new Merge[TSet[L|R], S]{ type Out = m.Out } |
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
class TSet[Items]{ | |
def merge[Obj](implicit m: Merge[Obj, Items]) = new TSet[m.Out] | |
} | |
trait Merge[LSet, RSet]{ | |
type Out | |
} | |
type |[A, B] = (A, B) |