Sequence two computations, disregarding the result of the first.
Sequence two computations, disregarding the result of the first.
val say = HttpOps[String].unit(println("Hello!")) val x = say andThen HttpOps[String].unit(3) scala> :t x com.pagerduty.sprayfunclient.Http[String, Int]
Like asFutureWithLog, but without the request log.
Like asFuture, but with the error computation as an Either type.
Finalize the HTTP computation without caring about the error type.
Finalize the HTTP computation without caring about the error type.
Any error value is converted to None.
Like asFuture, but in the case of error, the future is failed.
Like asFuture, but in the case of error, the future is failed.
This method requires that there is evidence that the error type is a sub-class of Throwable.
Finalize the HTTP computation by getting the underlying future value.
Finalize the HTTP computation by getting the underlying future value.
The result of the computation is the log of HTTP requests made as well as the computation (or the error that occurred).
import scala.concurrent._ import scala.concurrent.duration._ val x = HttpOps[String].unit(3) val fut = x.map(_ * 2).asFutureWithLog scala> Await.result(fut, Duration.Inf) res0: (Vector[LogEntry], \/[String,Int]) = (Vector(),\/-(6))
scala> :t HttpOps[String].unit(3) flatMap { x => HttpOps[String].unit(x.toDouble) } com.pagerduty.sprayfunclient.Http[String,Double]
Recover from errors.
Recover from errors.
val badComputation = HttpOps[String].raiseError[Int]("error1") for { x <- HttpOps[String].unit(5) y <- badComputation handleError { case "error1" => HttpOps[String].async(3) } } yield x + y
Map over the successful result of the computation.
Map over the successful result of the computation.
scala> :t HttpOps[String].unit(3).map(_.toDouble) com.pagerduty.sprayfunclient.Http[String,Double]
Map over the result of a failed computation.
Map over the result of a failed computation.
case class BadThing(message: String) val x = HttpOps[String].async(3) scala> :t x.mapError(BadThing.apply) com.pagerduty.sprayfunclient.Http[BadThing, Int]
A computation that involves remote requests over HTTP.
Http computations are asynchronous, log HTTP requests that are made, and have explicit error handling (without exceptions).
They have a simple functional interface consisting of:
as well as additional functions for error handling by-value.
Http computations can have one of two outcomes: an error of type
E
or a result of typeA
.Errors short-circuit computations and are threaded to the final result.
Http computations should be converted to Scala futures via asFuture or asFutureWithLog for further computation.
To those with functional programming experience, an Http is essentially a monad transformer consisting of an either, a writer, and a Scala Future.