Yoga.Om
- Package
- purescript-yoga-om
- Repository
- rowtype-yoga/purescript-yoga-om
#Om Source
newtype Om :: Type -> Row Type -> Type -> Typenewtype Om ctx err a
"dependency injection" via ReaderT which tracks a context, and
checked exceptions and early return with ExceptV.
Constructors
Instances
Newtype (Om ctx err a) _Functor (Om ctx err)Applicative (Om ctx err)Apply (Om ctx err)Bind (Om ctx err)Monad (Om ctx err)MonadEffect (Om ctx err)MonadAff (Om ctx err)MonadAsk ctx (Om ctx err)MonadReader ctx (Om ctx err)MonadThrow (Variant (Exception err)) (Om ctx err)MonadError (Variant (Exception err)) (Om ctx err)MonadRec (Om ctx err)(Semigroup a) => Semigroup (Om ctx err a)Alt (Om ctx err)Plus (Om ctx err)(RowToList ctx ctxRL, RowToList err errRL, Union ctx _c ctxRow, Keys ctx, Union err _e errRow) => Mapping (ExpandAndRun ctxRow errRow) (Om (Record ctx) err a) (Aff a)(IsSymbol sym, Cons sym a rb rc, Lacks sym rb, RowToList cSmall _cRL, RowToList eSmall _eRL, Union cSmall _c ctxRow, Keys cSmall, Union eSmall _e err) => FoldingWithIndex (SequenceOm ctxRow err) (Proxy sym) (Om (Record ctxRow) err (Builder (Record ra) (Record rb))) (Om (Record cSmall) eSmall a) (Om (Record ctxRow) err (Builder (Record ra) (Record rc)))(RowToList ctx ctxRL, RowToList err errRL) => Mapping CloseOmRows (Om (Record ctx) err a) (Om (Record ctx) err a)Parallel (ParOm ctx err) (Om ctx err)
#ParOm Source
#error Source
error :: forall err errors. SingletonVariantRecord err errors => Record err -> OneOfTheseErrors errors#expandCtx Source
expandCtx :: forall lt more gt err. Union lt more gt => Keys lt => (Om (Record lt) err) ~> (Om (Record gt) err)When you have a function that requires a closed subset of the context of
the one you're operating in, expandCtx allows to call this function in a
do block, e.g.:
let
otherComp :: Om { a :: A } _ _
otherComp = ...
myComp :: Om { a :: A, b :: B } _ _
myComp = do
...
otherComp # expandCtx
#handleErrors Source
handleErrors :: forall ctx errIn errOut a (handlersRL :: RowList Type) (handlers :: Row Type) (handled :: Row Type). RowToList handlers handlersRL => VariantMatchCases handlersRL handled (Om ctx errOut a) => Union handled (exception :: Error | errOut) (exception :: Error | errIn) => Record handlers -> Om ctx errIn a -> Om ctx errOut a#mapError Source
mapError :: forall @from @to tyIn tyOut ctx errIn errMid errOut a. IsSymbol from => IsSymbol to => Cons from tyIn (exception :: Error | errMid) (exception :: Error | errIn) => Cons to tyOut (exception :: Error | errMid) (exception :: Error | errOut) => (tyIn -> tyOut) -> Om ctx errIn a -> Om ctx errOut a#note Source
note :: forall m err errors a. SingletonVariantRecord err errors => MonadThrow (OneOfTheseErrors errors) m => Record err -> Maybe a -> m aTurns a Nothing into an exception which reduces nesting and encourages
tracking what actually went wrong
e.g.
do
let maybeCached = Object.lookup key cache :: Maybe a
cached :: a <- maybeCached # Om.note (unexpectedCacheMiss key)
#noteM Source
noteM :: forall err m a. MonadThrow err m => m err -> Maybe a -> m a#inParallel Source
inParallel :: forall ctx e a. Array (Om ctx e a) -> Om ctx e (Array a)Run multiple Oms in parallel, and collect all results
To only take the fastest result, use race
#runOm Source
runOm :: forall ctx r rl err_ err a. RowToList (exception :: Error -> Aff a | r) rl => VariantMatchCases rl err_ (Aff a) => Union err_ () (Exception err) => ctx -> { exception :: Error -> Aff a | r } -> Om ctx err a -> Aff aInvoke this function in the end and handle all possible errors, e.g.
runOm { token: "123" } { someError: \e -> handleTheError e } someApp
#runOmEffect Source
runOmEffect :: forall ctx a. ctx -> Om ctx () a -> Effect a#runOmRecord Source
runOmRecord :: forall ctxRow r rl err_ err rin closed rout. RowToList (exception :: Error -> Aff (Record rout) | r) rl => VariantMatchCases rl err_ (Aff (Record rout)) => Union err_ () (exception :: Error | err) => HMap CloseOmRows (Record rin) (Record closed) => HFoldlWithIndex (SequenceOm ctxRow err) (Om (Record ctxRow) err (Builder (Record ()) (Record ()))) (Record closed) (Om (Record ctxRow) err (Builder (Record ()) (Record rout))) => Record ctxRow -> { exception :: Error -> Aff (Record rout) | r } -> Record rin -> Aff (Record rout)Run a record of Om actions and return the results as a record.
Each field can be an Om with open context/error rows — they are
automatically expanded to the target context and error types.
runOmRecord ctx handlers
{ hello: Om.query @Queries @"hello" <#> _.hello
, users: Om.query @Queries @"users { name age }" <#> _.users
}
#sequenceOmRecord Source
sequenceOmRecord :: forall ctxRow err rin closed rout. HMap CloseOmRows (Record rin) (Record closed) => HFoldlWithIndex (SequenceOm ctxRow err) (Om (Record ctxRow) err (Builder (Record ()) (Record ()))) (Record closed) (Om (Record ctxRow) err (Builder (Record ()) (Record rout))) => Record rin -> Om (Record ctxRow) err (Record rout)#runOms Source
runOms :: forall ctxRow r rl err_ err rin closed rout. RowToList (exception :: Error -> Aff Unit | r) rl => VariantMatchCases rl err_ (Aff Unit) => Union err_ () (exception :: Error | err) => HMap CloseOmRows (Record rin) (Record closed) => HMap (ExpandAndRun ctxRow err) (Record closed) (Record rout) => Record ctxRow -> { exception :: Error -> Aff Unit | r } -> Record rin -> Record rout#runOmsInOm Source
runOmsInOm :: forall ctxRow r rl err_ err outerErr rin closed rout. RowToList (exception :: Error -> Aff Unit | r) rl => VariantMatchCases rl err_ (Aff Unit) => Union err_ () (exception :: Error | err) => HMap CloseOmRows (Record rin) (Record closed) => HMap (ExpandAndRun ctxRow err) (Record closed) (Record rout) => { exception :: Error -> Aff Unit | r } -> Record rin -> Om (Record ctxRow) outerErr (Record rout)#ExpandAndRun Source
#SequenceOm Source
data SequenceOm :: Row Type -> Row Type -> Typedata SequenceOm (ctxRow :: Row Type) (err :: Row Type)
Constructors
Instances
(IsSymbol sym, Cons sym a rb rc, Lacks sym rb, RowToList cSmall _cRL, RowToList eSmall _eRL, Union cSmall _c ctxRow, Keys cSmall, Union eSmall _e err) => FoldingWithIndex (SequenceOm ctxRow err) (Proxy sym) (Om (Record ctxRow) err (Builder (Record ra) (Record rb))) (Om (Record cSmall) eSmall a) (Om (Record ctxRow) err (Builder (Record ra) (Record rc)))
#CloseOmRows Source
#throw Source
throw :: forall m err errors a. SingletonVariantRecord err errors => MonadThrow (OneOfTheseErrors errors) m => Record err -> m a#throwLeftAs Source
throwLeftAs :: forall err m left right. MonadThrow err m => (left -> err) -> Either left right -> m rightTurns a Left a into an exception which reduces nesting
#throwLeftAsM Source
throwLeftAsM :: forall err m left right. MonadThrow err m => (left -> m err) -> Either left right -> m rightTurns a Left a into an exception which reduces nesting
#unliftAff Source
unliftAff :: forall ctx err otherErrors a. Om ctx err a -> Om ctx otherErrors (Aff (Either (Variant (Exception err)) a))Useful when constructing a parameterless callback of type Aff or
Effect within the context of an Om computation
recordAndUploadDOM ∷ Aff _ <- do
Om.unliftAff $ serialiseDOM >>= uploadDOMSnapshot
#unliftAffFn Source
unliftAffFn :: forall ctx arg errors a. (arg -> Om ctx () a) -> Om ctx errors (arg -> Aff a)Useful when constructing a callback of type Aff or Effect within the
context of an Om computation
uploadDOM ∷ (SerialisedDOM -> Aff _) <- do
Om.unliftAffFn $ uploadDOMSnapshot
#widenCtx Source
widenCtx :: forall err additionalCtx ctx widerCtx. Union additionalCtx ctx widerCtx => Nub widerCtx widerCtx => Record additionalCtx -> (Om (Record widerCtx) err) ~> (Om (Record ctx) err)Manually add some fields to the context of a computation.
This function is useful when already inside a do block of an Om
and you want to call a function that requires some ctx that you obtained
within this do block. For example:
do
moreCtx <- getSomeData :: Om {} _
getMoreData :: Om { moreCtx :: _ } _ # widenCtx { moreCtx }
Re-exports from Control.Monad.Reader.Trans
- Modules
- Yoga.
Om - Yoga.
Om. Error - Yoga.
Om. Ref - Yoga.
Om. Retry