Last active
December 14, 2015 04:39
-
-
Save Sciss/5029655 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
object Bar { | |
private var graphFun: Function0[Any] = () => () | |
def graph: () => Any = graphFun | |
def graph_=(fun: => Any) { | |
graphFun = () => fun | |
} | |
def boing() = graphFun() | |
} | |
Bar.graph = { println("Hallo") } | |
Bar.boing() | |
////////////////// | |
trait ZeroOut | |
object Out extends ZeroOut | |
object GE { | |
implicit def const(f: Float): GE = Const(f) | |
final case class Const(f: Float) extends GE | |
} | |
trait GE | |
object GraphFunction { | |
object Result { | |
implicit def in[T](implicit view: T => GE) = In(view) | |
implicit case object Out extends Result[ZeroOut] | |
final case class In[T](view: T => GE) extends Result[T] | |
} | |
sealed trait Result[-T] | |
} | |
object Foo { | |
private var res: GraphFunction.Result[_] = GraphFunction.Result.Out | |
private var fun: () => Any = () => () | |
def graph: () => Any = fun | |
def graph_=[T](body: => T)(implicit result: GraphFunction.Result[T]) { | |
res = result | |
fun = () => body | |
} | |
def apply() = fun() | |
} | |
Foo.graph = { println("Schoko"); 33f } | |
Foo() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment