
org.http4s.Service.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of http4s-core_2.10 Show documentation
Show all versions of http4s-core_2.10 Show documentation
Core http4s library for servers and clients
package org.http4s
import scalaz.Kleisli
import scalaz.concurrent.Task
import scalaz.syntax.kleisli._
object Service {
/**
* Lifts a total function that returns a Task into a [[Service]].
*
* @see [[HttpService.apply]]
*/
def lift[A, B](f: A => Task[B]): Service[A, B] = Kleisli.kleisli(f)
/**
* Lifts a Task into a [[Service]].
*
*/
def const[A, B](b: => Task[B]): Service[A, B] = b.liftKleisli
/**
* Lifts a value into a [[Service]].
*
*/
def constVal[A, B](b: => B): Service[A, B] = Task.now(b).liftKleisli
/**
* Allows Service chainig through an implicit [[Fallthrough]] instance.
*
*/
def withFallback[A, B : Fallthrough](fallback: Service[A, B])(service: Service[A, B]): Service[A, B] =
service.flatMap(resp => Fallthrough[B].fallthrough(resp, fallback))
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy