Last active
August 29, 2015 14:26
-
-
Save ejconlon/4edf92c28b5e29be06ab to your computer and use it in GitHub Desktop.
Elm Tasks, in Scala
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
package object tasks { | |
trait Task[A, B] { | |
private[tasks] def run(): Either[A, B] | |
def map[C](f: B => C): Task[A, C] = ??? | |
def flatMap[C](f: B => Task[A, C]): Task[A, C] = ??? | |
} | |
private[tasks] class Http[A, B]( | |
data: HttpRequest, | |
handler: Either[Throwable, HttpResponse] => Either[A, B], | |
executor: HttpRequest => Either[Throwable, HttpResponse] | |
) extends Task[A, B] { | |
override private[tasks] def run(): Either[A, B] = | |
handler(exectutor(data)) | |
} | |
object Http { | |
private[this] val executor: HttpRequest => HttpResponse = ??? | |
private[this] def mkGetRequest(url: Url): HttpRequest = ??? | |
def get(url: Url): Task[Thowable, HttpResponse] = | |
new Http(mkGetRequest(url), { x => x }, executor) | |
} | |
trait Port { | |
def submit[A, B](task: Task[A, B]): Either[A, B] = task.run() | |
} | |
object Port { | |
def mkPort: Port = new Port | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment