plutarch-extra-1.2.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Plutarch.Extra.Maybe

Synopsis

Utility functions for working with PMaybe

pfromJust :: forall (a :: PType) (s :: S). Term s (PMaybe a :--> a) Source #

Extracts the element out of a PJust and throws an error if its argument is PNothing.

ptraceIfNothing Source #

Arguments

:: forall (a :: PType) (s :: S). Term s PString

The custom error message.

-> Term s (PMaybe a) 
-> Term s a 

Extracts the element out of a PJust and throws a custom error if it's given a PNothing.

pisJust :: forall (a :: PType) (s :: S). Term s (PMaybe a :--> PBool) Source #

Yields true if the given PMaybe value is of form PJust _.

pmaybe :: forall (b :: PType) (a :: PType) (s :: S). Term s (b :--> ((a :--> b) :--> (PMaybe a :--> b))) Source #

Given a default value, a function and a PMaybe value, yields the default value if the PMaybe value is PNothing and applies the function to the value stored in the PJust otherwise.

pfromMaybe :: forall (a :: PType) (s :: S). Term s (a :--> (PMaybe a :--> a)) Source #

Extract a PMaybe by providing a default value in case of PJust.

pjust :: forall (a :: PType) (s :: S). Term s (a :--> PMaybe a) Source #

Construct a PJust value.

pnothing :: forall (a :: PType) (s :: S). Term s (PMaybe a) Source #

Construct a PNothing value.

Utility functions for working with PMaybeData

pfromDJust :: forall (a :: PType) (s :: S). PIsData a => Term s (PMaybeData a :--> a) Source #

Extracts the element out of a PDJust and throws an error if its argument is PDNothing.

pisDJust :: forall (a :: PType) (s :: S). Term s (PMaybeData a :--> PBool) Source #

Yield True if a given PMaybeData is of form PDJust _.

pmaybeData :: forall (a :: PType) (b :: PType) (s :: S). PIsData a => Term s (b :--> ((a :--> b) :--> (PMaybeData a :--> b))) Source #

Special version of pmaybe that works with PMaybeData

pdjust :: forall (a :: PType) (s :: S). PIsData a => Term s (a :--> PMaybeData a) Source #

Construct a PDJust value

pdnothing :: forall (a :: PType) (s :: S). Term s (PMaybeData a) Source #

Construct a PDNothing value

Conversion between PMaybe and PMaybeData

pmaybeToMaybeData :: forall (a :: PType) (s :: S). PIsData a => Term s (PMaybe a :--> PMaybeData a) Source #

Copnsturct a PMaybeData given a PMaybe. Could be useful if you want to "lift" from PMaybe to Maybe.

TermCont-based combinators

pexpectJustC :: forall (a :: PType) (r :: PType) (s :: S). Term s r -> Term s (PMaybe a) -> TermCont @r s (Term s a) Source #

Escape with a particular value on expecting Just. For use in monadic context.

Assertions

passertPJust :: forall (a :: PType) (s :: S). Term s (PString :--> (PMaybe a :--> a)) Source #

Extract the value stored in a PMaybe container. If there's no value, throw an error with the given message.

passertPDJust :: forall (a :: PType) (s :: S). PIsData a => Term s (PString :--> (PMaybeData a :--> a)) Source #

Extract the value stored in a PMaybeData container. If there's no value, throw an error with the given message.