mirror of https://github.com/sbt/sbt.git
conversions
This commit is contained in:
parent
aaa36f6cd2
commit
899920a0a0
|
|
@ -1,17 +0,0 @@
|
|||
package xsbt
|
||||
|
||||
import HLists._
|
||||
import Task._
|
||||
|
||||
/** This test just verifies that the HList support compiles.*/
|
||||
object TListCompileTest
|
||||
{
|
||||
val n = Task(1)
|
||||
val s = Task("3")
|
||||
val t = Task(true)
|
||||
val mapped = (n :: s :: t :: TNil) map { case n :: s :: t :: HNil => n }
|
||||
val bound = (n :: s :: t :: TNil) bind { case n :: s :: t :: HNil => (Task(n*4) :: Task("Hi " + t) :: TNil).join }
|
||||
|
||||
val plusOne = mapped map { _ + 1 }
|
||||
val forkN = plusOne bind { count => (0 until count) fork { i => Task(println(i)) } join }
|
||||
}
|
||||
|
|
@ -25,4 +25,10 @@ final case class HCons[H, T <: HList](head : H, tail : T) extends HList
|
|||
type Up = MCons[H, tail.Up, Id]
|
||||
def up = MCons[H,tail.Up, Id](head, tail.up)
|
||||
def :+: [G](g: G): G :+: H :+: T = HCons(g, this)
|
||||
}
|
||||
|
||||
object HList
|
||||
{
|
||||
// contains no type information: not even A
|
||||
implicit def fromList[A](list: Traversable[A]): HList = ((HNil: HList) /: list) ( (hl,v) => HCons(v, hl) )
|
||||
}
|
||||
|
|
@ -41,4 +41,11 @@ sealed class MNil extends MList[Nothing]
|
|||
|
||||
def toList = Nil
|
||||
}
|
||||
object MNil extends MNil
|
||||
object MNil extends MNil
|
||||
|
||||
|
||||
object MList
|
||||
{
|
||||
implicit def fromTCList[A[_]](list: Traversable[A[_]]): MList[A] = ((MNil: MList[A]) /: list) ( (hl,v) => MCons(v, hl) )
|
||||
implicit def fromList[A](list: Traversable[A]): MList[Const[A]#Apply] = ((MNil: MList[Const[A]#Apply]) /: list) ( (hl,v) => MCons[A, hl.type, Const[A]#Apply](v, hl) )
|
||||
}
|
||||
|
|
@ -13,6 +13,10 @@ trait TypeFunctions
|
|||
final val left = new (Id ~> P1of2[Left, Nothing]#Flip) { def apply[T](t: T) = Left(t) }
|
||||
final val right = new (Id ~> P1of2[Right, Nothing]#Apply) { def apply[T](t: T) = Right(t) }
|
||||
final val some = new (Id ~> Some) { def apply[T](t: T) = Some(t) }
|
||||
|
||||
implicit def toFn1[A,B](f: A => B): Fn1[A,B] = new Fn1[A,B] {
|
||||
def ∙[C](g: C => A) = f compose g
|
||||
}
|
||||
}
|
||||
object TypeFunctions extends TypeFunctions
|
||||
|
||||
|
|
@ -29,4 +33,7 @@ object ~>
|
|||
import TypeFunctions._
|
||||
val Id: Id ~> Id = new (Id ~> Id) { def apply[T](a: T): T = a }
|
||||
implicit def tcIdEquals: (Id ~> Id) = Id
|
||||
}
|
||||
trait Fn1[A, B] {
|
||||
def ∙[C](g: C => A): C => B
|
||||
}
|
||||
Loading…
Reference in New Issue