Created
October 25, 2014 13:14
-
-
Save wheaties/cb7f03aad225a2a7376d to your computer and use it in GitHub Desktop.
Dependent Function1
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 DepFunction1[T]{ self => | |
type R | |
def apply(t: T): R | |
def andThen(dep: DepFunction1[R]): Aux[T, dep.R] = new DepFunction1[T]{ | |
type R = dep.R | |
def apply(t: T) = dep(self(t)) | |
} | |
def compose[A](dep: Aux[A, T]): Aux[A, R] = dep andThen self | |
def andThen[A](f: R => A): Aux[T, A] = new DepFunction1[T]{ | |
type R = A | |
def apply(t: T) = f(self(t)) | |
} | |
def compose[A](f: A => T): Aux[A, R] = new DepFunction1[A]{ | |
type R = self.R | |
def apply(a: A) = self(f(a)) | |
} | |
} | |
object DepFunction1{ | |
type Aux[T, R0] = DepFunction1[T]{ type R = R0 } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment