HORIZON HASKELLDocslts/ghc-10.0.x8fef28d2026-11-02Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8fef28d · 2026-11-02

  • Packageopaleye-0.10.8.0
  • Exports31
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceMaybeFields.hs
datadata MaybeFields fields

The Opaleye analogue of Maybe. A value of type MaybeFields a either contains a value of type a, or it contains nothing.

Instances12Monad, Functor, Applicative, Default, …

Creating a MaybeFields

Using a MaybeFields

Creating a Select which returns MaybeFields

valueoptional
  1. :: Default Unpackspec a a
  2. => SelectArr i a

    Input query

  3. -> SelectArr i (MaybeFields a)

    The rows of the input query wrapped in "Just", unless the input query has no rows in which case a single row of "Nothing"

Convenient access to lateral left/right join functionality. Performs a LATERAL LEFT JOIN under the hood and has behaviour equivalent to the following Haskell function:

optional :: [a] -> [Maybe a]
optional q = case q of
    [] -> [Nothing]
    xs -> map Just xs

That is, if q :: SelectArr i a returns no rows, optional q :: SelectArr i (MaybeFields a) returns exactly one "Nothing" row. Otherwise, optional q returns exactly the rows of q wrapped in "Just". For example,

> let l1 = ["one", "two", "three"] :: [Field SqlText]
> runSelectI conn (optional (values l1))
[Just "one", Just "two", Just "three"]

> let l2 = [] :: [Field SqlText]
> runSelectI conn (optional (values l2))
[Nothing]

optionalRestrict is a special case of optional and could be written in terms of optional as follows (except that optionalRestrict doesn't use LATERAL under the hood and optional does).

optionalRestrict q = optional $ proc cond -> do
  a <- q -< ()
  restrict -< cond a
  returnA -< a

Using a Select which returns MaybeFields

Adaptors

newtypenewtype Nullspec fields fields'
#
Instances5Profunctor, ProductProfunctor, Default, Functor, Applicative

Explicit versions