Packages

final class ZQuery[-R, +E, +A] extends AnyRef

A ZQuery[R, E, A] is a purely functional description of an effectual query that may contain requests from one or more data sources, requires an environment R, and may fail with an E or succeed with an A.

Requests that can be performed in parallel, as expressed by zipWithPar and combinators derived from it, will automatically be batched. Requests that must be performed sequentially, as expressed by zipWith and combinators derived from it, will automatically be pipelined. This allows for aggressive data source specific optimizations. Requests can also be deduplicated and cached.

This allows for writing queries in a high level, compositional style, with confidence that they will automatically be optimized. For example, consider the following query from a user service.

val getAllUserIds: ZQuery[Any, Nothing, List[Int]]         = ???
def getUserNameById(id: Int): ZQuery[Any, Nothing, String] = ???

for {
  userIds   <- getAllUserIds
  userNames <- ZQuery.foreachPar(userIds)(getUserNameById)
} yield userNames

This would normally require N + 1 queries, one for getAllUserIds and one for each call to getUserNameById. In contrast, ZQuery will automatically optimize this to two queries, one for userIds and one for userNames, assuming an implementation of the user service that supports batching.

Based on "There is no Fork: an Abstraction for Efficient, Concurrent, and Concise Data Access" by Simon Marlow, Louis Brandy, Jonathan Coens, and Jon Purdy. http://simonmar.github.io/bib/papers/haxl-icfp14.pdf

Self Type
ZQuery[R, E, A]
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. ZQuery
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def &>[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, B]

    A symbolic alias for zipParRight.

  4. final def *>[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, B]

    A symbolic alias for zipRight.

  5. final def <&[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, A]

    A symbolic alias for zipParLeft.

  6. final def <&>[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, (A, B)]

    A symbolic alias for zipPar.

  7. final def <*[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, A]

    A symbolic alias for zipLeft.

  8. final def <*>[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, (A, B)]

    A symbolic alias for zip.

  9. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  10. final def >>=[R1 <: R, E1 >: E, B](f: (A) ⇒ ZQuery[R1, E1, B]): ZQuery[R1, E1, B]

    A symbolic alias for flatMap.

  11. final def @@[R1 <: R](aspect: DataSourceAspect[R1]): ZQuery[R1, E, A]

    Syntax for adding aspects.

  12. def absolve[E1 >: E, B](implicit ev: <:<[A, Either[E1, B]]): ZQuery[R, E1, B]

    Returns a query which submerges the error case of Either into the error channel of the query

    Returns a query which submerges the error case of Either into the error channel of the query

    The inverse of ZQuery.either

  13. final def as[B](b: ⇒ B): ZQuery[R, E, B]

    Maps the success value of this query to the specified constant value.

  14. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  15. def asSomeError: ZQuery[R, Option[E], A]

    Lifts the error channel into a Some value for composition with other optional queries

    Lifts the error channel into a Some value for composition with other optional queries

    See also

    ZQuery.some

  16. final def bimap[E1, B](f: (E) ⇒ E1, g: (A) ⇒ B)(implicit ev: CanFail[E]): ZQuery[R, E1, B]

    Returns a query whose failure and success channels have been mapped by the specified pair of functions, f and g.

  17. def catchAll[R1 <: R, E2, A1 >: A](h: (E) ⇒ ZQuery[R1, E2, A1])(implicit ev: CanFail[E]): ZQuery[R1, E2, A1]

    Recovers from all errors.

  18. def catchAllCause[R1 <: R, E2, A1 >: A](h: (Cause[E]) ⇒ ZQuery[R1, E2, A1]): ZQuery[R1, E2, A1]

    Recovers from all errors with provided Cause.

    Recovers from all errors with provided Cause.

    See also

    ZQuery.sandbox - other functions that can recover from defects

  19. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  20. def collectSome[E1](implicit ev: <:<[E, Option[E1]]): ZQuery[R, E1, Option[A]]

    Moves a None value in the error channel into the value channel while converting the existing value into a Some

    Moves a None value in the error channel into the value channel while converting the existing value into a Some

    Inverse of ZQuery.some

  21. final def either(implicit ev: CanFail[E]): ZQuery[R, Nothing, Either[E, A]]

    Returns a query whose failure and success have been lifted into an Either.

    Returns a query whose failure and success have been lifted into an Either. The resulting query cannot fail, because the failure case has been exposed as part of the Either success case.

  22. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  23. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  24. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  25. final def flatMap[R1 <: R, E1 >: E, B](f: (A) ⇒ ZQuery[R1, E1, B]): ZQuery[R1, E1, B]

    Returns a query that models execution of this query, followed by passing its result to the specified function that returns a query.

    Returns a query that models execution of this query, followed by passing its result to the specified function that returns a query. Requests composed with flatMap or combinators derived from it will be executed sequentially and will not be pipelined, though deduplication and caching of requests may still be applied.

  26. final def flatten[R1 <: R, E1 >: E, B](implicit ev: <:<[A, ZQuery[R1, E1, B]]): ZQuery[R1, E1, B]

    Returns a query that performs the outer query first, followed by the inner query, yielding the value of the inner query.

    Returns a query that performs the outer query first, followed by the inner query, yielding the value of the inner query.

    This method can be used to "flatten" nested queries.

  27. final def fold[B](failure: (E) ⇒ B, success: (A) ⇒ B)(implicit ev: CanFail[E]): ZQuery[R, Nothing, B]

    Folds over the failed or successful result of this query to yield a query that does not fail, but succeeds with the value returned by the left or right function passed to fold.

  28. final def foldCauseM[R1 <: R, E1, B](failure: (Cause[E]) ⇒ ZQuery[R1, E1, B], success: (A) ⇒ ZQuery[R1, E1, B]): ZQuery[R1, E1, B]

    A more powerful version of foldM that allows recovering from any type of failure except interruptions.

  29. final def foldM[R1 <: R, E1, B](failure: (E) ⇒ ZQuery[R1, E1, B], success: (A) ⇒ ZQuery[R1, E1, B])(implicit ev: CanFail[E]): ZQuery[R1, E1, B]

    Recovers from errors by accepting one query to execute for the case of an error, and one query to execute for the case of success.

  30. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  31. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  32. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  33. final def left[B, C](implicit ev: <:<[A, Either[B, C]]): ZQuery[R, Option[E], B]

    Returns a successful query if the value is Left, or fails with the error None.

  34. final def leftOrFail[B, C, E1 >: E](e: ⇒ E1)(implicit ev: <:<[A, Either[B, C]]): ZQuery[R, E1, B]

    Returns a successful query if the value is Left, or fails with the error e.

  35. final def leftOrFailWith[B, C, E1 >: E](e: (C) ⇒ E1)(implicit ev: <:<[A, Either[B, C]]): ZQuery[R, E1, B]

    Returns a successful query if the value is Left, or fails with the given error function 'e'.

  36. final def map[B](f: (A) ⇒ B): ZQuery[R, E, B]

    Maps the specified function over the successful result of this query.

  37. final def mapDataSources[R1 <: R](f: DataSourceAspect[R1]): ZQuery[R1, E, A]

    Transforms all data sources with the specified data source aspect.

  38. final def mapError[E1](f: (E) ⇒ E1)(implicit ev: CanFail[E]): ZQuery[R, E1, A]

    Maps the specified function over the failed result of this query.

  39. def mapErrorCause[E2](h: (Cause[E]) ⇒ Cause[E2]): ZQuery[R, E2, A]

    Returns a query with its full cause of failure mapped using the specified function.

    Returns a query with its full cause of failure mapped using the specified function. This can be used to transform errors while preserving the original structure of Cause.

    See also

    sandbox, catchAllCause - other functions for dealing with defects

  40. final def mapM[R1 <: R, E1 >: E, B](f: (A) ⇒ ZIO[R1, E1, B]): ZQuery[R1, E1, B]

    Maps the specified effectual function over the result of this query.

  41. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  42. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  43. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  44. final def optional: ZQuery[R, E, Option[A]]

    Converts this query to one that returns Some if data sources return results for all requests received and None otherwise.

  45. final def orDie(implicit ev1: <:<[E, Throwable], ev2: CanFail[E]): ZQuery[R, Nothing, A]

    Converts this query to one that dies if a query failure occurs.

  46. final def orDieWith(f: (E) ⇒ Throwable)(implicit ev: CanFail[E]): ZQuery[R, Nothing, A]

    Converts this query to one that dies if a query failure occurs, using the specified function to map the error to a Throwable.

  47. final def provide(r: Described[R])(implicit ev: NeedsEnv[R]): ZQuery[Any, E, A]

    Provides this query with its required environment.

  48. final def provideCustomLayer[E1 >: E, R1 <: Has[_]](layer: Described[ZLayer[zio.ZEnv, E1, R1]])(implicit ev: <:<[zio.ZEnv with R1, R], tag: zio.Tag[R1]): ZQuery[zio.ZEnv, E1, A]

    Provides the part of the environment that is not part of the ZEnv, leaving a query that only depends on the ZEnv.

  49. final def provideLayer[E1 >: E, R0, R1 <: Has[_]](layer: Described[ZLayer[R0, E1, R1]])(implicit ev1: <:<[R1, R], ev2: NeedsEnv[R]): ZQuery[R0, E1, A]

    Provides a layer to this query, which translates it to another level.

  50. final def provideSome[R0](f: Described[(R0) ⇒ R])(implicit ev: NeedsEnv[R]): ZQuery[R0, E, A]

    Provides this query with part of its required environment.

  51. final def provideSomeLayer[R0 <: Has[_]]: ProvideSomeLayer[R0, R, E, A]

    Splits the environment into two parts, providing one part using the specified layer and leaving the remainder R0.

  52. def refineOrDie[E1](pf: PartialFunction[E, E1])(implicit ev1: <:<[E, Throwable], ev2: CanFail[E]): ZQuery[R, E1, A]

    Keeps some of the errors, and terminates the query with the rest

  53. def refineOrDieWith[E1](pf: PartialFunction[E, E1])(f: (E) ⇒ Throwable)(implicit ev: CanFail[E]): ZQuery[R, E1, A]

    Keeps some of the errors, and terminates the query with the rest, using the specified function to convert the E into a Throwable.

  54. def right[B, C](implicit ev: <:<[A, Either[B, C]]): ZQuery[R, Option[E], C]

    Returns a successful effect if the value is Right, or fails with the error None.

  55. def rightOrFail[B, C, E1 >: E](e: ⇒ E1)(implicit ev: <:<[A, Either[B, C]]): ZQuery[R, E1, C]

    Returns a successful effect if the value is Right, or fails with the given error 'e'.

  56. def rightOrFailWith[B, C, E1 >: E](e: (B) ⇒ E1)(implicit ev: <:<[A, Either[B, C]]): ZQuery[R, E1, C]

    Returns a successful effect if the value is Right, or fails with the given error function 'e'.

  57. final val run: ZIO[R, E, A]

    Returns an effect that models executing this query.

  58. final def runCache(cache: Cache): ZIO[R, E, A]

    Returns an effect that models executing this query with the specified cache.

  59. final def runLog: ZIO[R, E, (Cache, A)]

    Returns an effect that models executing this query, returning the query result along with the cache.

  60. def sandbox: ZQuery[R, Cause[E], A]

    Expose the full cause of failure of this query

  61. def sandboxWith[R1 <: R, E2, B](f: (ZQuery[R1, Cause[E], A]) ⇒ ZQuery[R1, Cause[E2], B]): ZQuery[R1, E2, B]

    Companion helper to sandbox.

    Companion helper to sandbox. Allows recovery, and partial recovery, from errors and defects alike, as in:

  62. def some[B](implicit ev: <:<[A, Option[B]]): ZQuery[R, Option[E], B]

    Extracts a Some value into the value channel while moving the None into the error channel for easier composition

    Extracts a Some value into the value channel while moving the None into the error channel for easier composition

    Inverse of ZQuery.collectSome

  63. final def someOrFail[B, E1 >: E](e: ⇒ E1)(implicit ev: <:<[A, Option[B]]): ZQuery[R, E1, B]

    Extracts the optional value or fails with the given error e.

  64. final def summarized[R1 <: R, E1 >: E, B, C](summary: ZIO[R1, E1, B])(f: (B, B) ⇒ C): ZQuery[R1, E1, (C, A)]

    Summarizes a query by computing some value before and after execution, and then combining the values to produce a summary, together with the result of execution.

  65. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  66. final def timed: ZQuery[R with Clock, E, (Duration, A)]

    Returns a new query that executes this one and times the execution.

  67. def toString(): String
    Definition Classes
    AnyRef → Any
  68. final def unrefine[E1 >: E](pf: PartialFunction[Throwable, E1]): ZQuery[R, E1, A]

    Takes some fiber failures and converts them into errors.

  69. final def unrefineTo[E1 >: E](implicit arg0: ClassTag[E1]): ZQuery[R, E1, A]

    Takes some fiber failures and converts them into errors.

  70. final def unrefineWith[E1](pf: PartialFunction[Throwable, E1])(f: (E) ⇒ E1): ZQuery[R, E1, A]

    Takes some fiber failures and converts them into errors, using the specified function to convert the E into an E1.

  71. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  72. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  73. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  74. final def zip[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, (A, B)]

    Returns a query that models the execution of this query and the specified query sequentially, combining their results into a tuple.

  75. final def zipBatched[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, (A, B)]

    Returns a query that models the execution of this query and the specified query, batching requests to data sources and combining their results into a tuple.

  76. final def zipBatchedLeft[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, A]

    Returns a query that models the execution of this query and the specified query, batching requests to data sources and returning the result of this query.

  77. final def zipBatchedRight[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, B]

    Returns a query that models the execution of this query and the specified query, batching requests to data sources and returning the result of the specified query.

  78. final def zipLeft[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, A]

    Returns a query that models the execution of this query and the specified query sequentially, returning the result of this query.

  79. final def zipPar[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, (A, B)]

    Returns a query that models the execution of this query and the specified query in parallel, combining their results into a tuple.

  80. final def zipParLeft[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, A]

    Returns a query that models the execution of this query and the specified query in parallel, returning the result of this query.

  81. final def zipParRight[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, B]

    Returns a query that models the execution of this query and the specified query in parallel, returning the result of the specified query.

  82. final def zipRight[R1 <: R, E1 >: E, B](that: ZQuery[R1, E1, B]): ZQuery[R1, E1, B]

    Returns a query that models the execution of this query and the specified query sequentially, returning the result of the specified query.

  83. final def zipWith[R1 <: R, E1 >: E, B, C](that: ZQuery[R1, E1, B])(f: (A, B) ⇒ C): ZQuery[R1, E1, C]

    Returns a query that models the execution of this query and the specified query sequentially, combining their results with the specified function.

    Returns a query that models the execution of this query and the specified query sequentially, combining their results with the specified function. Requests composed with zipWith or combinators derived from it will automatically be pipelined.

  84. final def zipWithBatched[R1 <: R, E1 >: E, B, C](that: ZQuery[R1, E1, B])(f: (A, B) ⇒ C): ZQuery[R1, E1, C]

    Returns a query that models the execution of this query and the specified query, batching requests to data sources.

  85. final def zipWithPar[R1 <: R, E1 >: E, B, C](that: ZQuery[R1, E1, B])(f: (A, B) ⇒ C): ZQuery[R1, E1, C]

    Returns a query that models the execution of this query and the specified query in parallel, combining their results with the specified function.

    Returns a query that models the execution of this query and the specified query in parallel, combining their results with the specified function. Requests composed with zipWithPar or combinators derived from it will automatically be batched.

Inherited from AnyRef

Inherited from Any

Ungrouped