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
#OptionsRL Source
class OptionsRL :: RowList Type -> RowList Type -> Constraintclass OptionsRL givenRL fullRL
Instances
OptionsRL Nil fullRL(LookupField label fullRL fullType, OptionsFieldType givenType fullType, OptionsRL givenRL fullRL) => OptionsRL (Cons label givenType givenRL) fullRL
#LookupField Source
class LookupField :: Symbol -> RowList Type -> Type -> Constraintclass LookupField label rl ty | label rl -> ty
Instances
LookupField label (Cons label ty tail) ty(LookupField label tail ty) => LookupField label (Cons other ty' tail) ty
#OptionsFieldType Source
class OptionsFieldType from to Instances
OptionsFieldType Undefined a(RowToList r1 rl1, RowToList r2 rl2, OptionsRL rl1 rl2) => OptionsFieldType (Record r1) (UndefinedOr (Record r2))OptionsFieldType a (UndefinedOr a)OptionsFieldType a (Identity a)OptionsFieldType a a
#nullishCoalesce Source
nullishCoalesce :: forall a. UndefinedOr a -> a -> aRe-exports from Untagged.Union
#UndefinedOr Source
type UndefinedOr a = OneOf Undefined a#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