HORIZON HASKELLDocslts/ghc-10.0.x8c2f8e82026-10-19Search names, modules, packages, or :: a typeCtrl K

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 8c2f8e8 · 2026-10-19

Moduleopaleye-0.10.8.0Haskell2010

Opaleye.MaybeFields

MaybeFields is Opaleye's analogue to Maybe. You probably won't want to create values of type MaybeFields directly; instead they will appear as the result of left/right/outer join-like operations, such as optionalRestrict and optional.

  • 2 types
  • 29 values
  • Packageopaleye-0.10.8.0
  • Exports31
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceMaybeFields.hs

MaybeFields type

1 declaration
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

4 declarations

Using a MaybeFields

5 declarations
valuematchMaybe :: Default IfPP b b => MaybeFields a -> (Maybe a -> b) -> b
#

Use a Haskell \case expression to pattern match on a MaybeFields.

example :: MaybeFields (Field SqlInt4) -> Field SqlInt4
example mf = matchMaybe mf $ \case
  Nothing -> 0
  Just x  -> x * 100

Creating a Select which returns MaybeFields

2 declarations
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

2 declarations

Adaptors

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

Explicit versions

5 declarations