Module

Yoga.Options

Package
purescript-yoga-options
Repository
rowtype-yoga/purescript-yoga-options

Ergonomic optional fields for PureScript records.

Define a row type with f-wrapped optional fields, resolve it with OneOf Undefined, then use options to accept any subset:

type MyConfigR f =
  ( host :: String
  , port :: Int
  , ssl :: f Boolean
  )
type MyConfig = MyConfigR (OneOf Undefined)

myFunction :: forall r. Options r MyConfig => { | r } -> Result
myFunction given = do
  let config = options @MyConfig given
  let ssl = uorToMaybe config.ssl    -- Maybe Boolean
  let ssl' = config.ssl ?? false     -- Boolean

#Options Source

class Options :: Row Type -> Row Type -> Constraintclass Options given full 

Instances

#options Source

options :: forall @full given. Options given full => Record given -> Record full

#OptionsRL Source

class OptionsRL :: RowList Type -> RowList Type -> Constraintclass OptionsRL givenRL fullRL 

Instances

#LookupField Source

class LookupField :: Symbol -> RowList Type -> Type -> Constraintclass LookupField label rl ty | label rl -> ty

Instances

#nullishCoalesce Source

nullishCoalesce :: forall a. UndefinedOr a -> a -> a

#(??) Source

Operator alias for Yoga.Options.nullishCoalesce (left-associative / precedence 9)

Re-exports from Untagged.Union

#UndefinedOr Source

#withUor Source

withUor :: forall a b. (a -> b) -> UndefinedOr a -> UndefinedOr b

#uorToMaybe Source

uorToMaybe :: forall a. UndefinedOr a -> Maybe a

#fromUndefinedOr Source

fromUndefinedOr :: forall a. a -> UndefinedOr a -> a

#defined Source

defined :: forall a. a -> UndefinedOr a
Modules
Yoga.Options