Created
November 6, 2017 00:32
-
-
Save andyscott/876862296aff4bc98909954d374da2a6 to your computer and use it in GitHub Desktop.
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
def foldTo[B]: CopFoldTo[B] = new CopFoldTo[B] | |
class CopFoldTo[B] { | |
def apply[L <: TList, LF <: TList](a: Cop[L])(fs: Prod[LF])( | |
implicit ev: TList.Compute.Aux[Op.Map[? => B, L], LF] | |
): B = | |
fs.values(a.index).asInstanceOf[Any => B].apply(a.value) | |
} | |
object Finn | |
object Cinder | |
object Bridger | |
type Dog = Cop[Finn.type :: Cinder.type :: Bridger.type :: TNil] | |
val dog0 = Finn.inject[Dog] | |
val dog1 = Cinder.inject[Dog] | |
val res = foldTo[String](dog0)(Prod( | |
(finn: Finn.type) => s"we got finn $finn", | |
(cinder: Cinder.type) => s"we got cinder $cinder", | |
(bridger: Bridger.type) => s"we got bridger $bridger")) | |
println(res) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment