{-# LANGUAGE QuantifiedConstraints #-}

module Plutarch.Extra.Traversable (
  -- * Type classes
  PTraversable (..),
  PSemiTraversable (..),

  -- * Functions

  -- ** Folds
  psemifold,
  psemifoldMap,
  psemifoldComonad,
  pfold,
  pfoldMap,
  pfoldComonad,

  -- ** Specialized folds
  psum,
  Plutarch.Extra.Traversable.plength,
  Plutarch.Extra.Traversable.pany,
  Plutarch.Extra.Traversable.pall,
) where

import Plutarch.Api.V1.Maybe (PMaybeData (PDJust, PDNothing))
import Plutarch.Extra.Applicative (
  PApplicative (ppure),
  PApply (pliftA2),
  (#*>),
 )
import Plutarch.Extra.Boring (PBoring (pboring))
import Plutarch.Extra.Comonad (PComonad (pextract))
import Plutarch.Extra.Const (PConst (PConst), preconst)
import Plutarch.Extra.Functor (PFunctor (PSubcategory, pfmap))
import Plutarch.Extra.Identity (PIdentity (PIdentity))
import Plutarch.Extra.Monoid (
  PAll (PAll),
  PAny (PAny),
  pgetAll,
  pgetAny,
 )
import Plutarch.Extra.Sum (PSum (PSum))
import Plutarch.Extra.TermCont (pletC, pmatchC)
import Plutarch.List (puncons)
import Plutarch.Num (PNum)

-- | @since 1.0.0
class (PFunctor t) => PTraversable (t :: (S -> Type) -> S -> Type) where
  ptraverse ::
    forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (b :: S -> Type) (s :: S).
    ( PApplicative f
    , PSubcategory f a
    , PSubcategory f b
    , PSubcategory f (t b)
    , PSubcategory t a
    , PSubcategory t b
    ) =>
    Term s ((a :--> f b) :--> t a :--> f (t b))

  -- | This avoids re-building the input 'PTraversable' if we end up throwing
  -- it away anyway. In the case where we only care about the effect, and
  -- don't need the 'PTraversable' afterwards, this can be more efficient.
  --
  -- = Note
  --
  -- This is \'boredom-polymorphic\' to ensure that we don't run into issues
  -- with 'PSubcategory' constraints. This is why we choose the order of type
  -- variables as we do: it allows you to easily choose which 'PBoring' thing
  -- you want.
  --
  -- @since 1.2.0
  ptraverse_ ::
    forall
      (b :: S -> Type)
      (f :: (S -> Type) -> S -> Type)
      (a :: S -> Type)
      (s :: S).
    ( PApplicative f
    , PSubcategory f b
    , PBoring b
    , PSubcategory t a
    ) =>
    Term s ((a :--> f b) :--> t a :--> f b)

-- | @since 1.0.0
instance PTraversable PIdentity where
  ptraverse :: forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f a, PSubcategory f b,
 PSubcategory f (PIdentity b), PSubcategory PIdentity a,
 PSubcategory PIdentity b) =>
Term s ((a :--> f b) :--> (PIdentity a :--> f (PIdentity b)))
ptraverse = forall (t :: (S -> Type) -> S -> Type)
       (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (b :: S -> Type)
       (s :: S).
(PSemiTraversable t, PApply f, PSubcategory f a, PSubcategory f b,
 PSubcategory f (t b)) =>
Term s ((a :--> f b) :--> (t a :--> f (t b)))
psemitraverse
  ptraverse_ :: forall (b :: S -> Type) (f :: (S -> Type) -> S -> Type)
       (a :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f b, PBoring b,
 PSubcategory PIdentity a) =>
Term s ((a :--> f b) :--> (PIdentity a :--> f b))
ptraverse_ = forall (t :: (S -> Type) -> S -> Type) (b :: S -> Type)
       (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PSemiTraversable t, PApply f, PSubcategory f b, PBoring b,
 PSubcategory t a) =>
Term s ((a :--> f b) :--> (t a :--> f b))
psemitraverse_

-- | @since 1.0.0
instance PTraversable PSum where
  ptraverse :: forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f a, PSubcategory f b,
 PSubcategory f (PSum b), PSubcategory PSum a,
 PSubcategory PSum b) =>
Term s ((a :--> f b) :--> (PSum a :--> f (PSum b)))
ptraverse = forall (t :: (S -> Type) -> S -> Type)
       (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (b :: S -> Type)
       (s :: S).
(PSemiTraversable t, PApply f, PSubcategory f a, PSubcategory f b,
 PSubcategory f (t b)) =>
Term s ((a :--> f b) :--> (t a :--> f (t b)))
psemitraverse
  ptraverse_ :: forall (b :: S -> Type) (f :: (S -> Type) -> S -> Type)
       (a :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f b, PBoring b,
 PSubcategory PSum a) =>
Term s ((a :--> f b) :--> (PSum a :--> f b))
ptraverse_ = forall (t :: (S -> Type) -> S -> Type) (b :: S -> Type)
       (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PSemiTraversable t, PApply f, PSubcategory f b, PBoring b,
 PSubcategory t a) =>
Term s ((a :--> f b) :--> (t a :--> f b))
psemitraverse_

-- | @since 1.0.0
instance PTraversable (PConst a) where
  ptraverse :: forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f a, PSubcategory f b,
 PSubcategory f (PConst a b), PSubcategory (PConst a) a,
 PSubcategory (PConst a) b) =>
Term s ((a :--> f b) :--> (PConst a a :--> f (PConst a b)))
ptraverse = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$
    forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (a :--> f b)
_ Term s (PConst a a)
t ->
      forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f a) =>
Term s (a :--> f a)
ppure forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall (c :: S -> Type) (a :: S -> Type) (b :: S -> Type) (s :: S).
Term s (PConst a b) -> Term s (PConst a c)
preconst Term s (PConst a a)
t
  ptraverse_ :: forall (b :: S -> Type) (f :: (S -> Type) -> S -> Type)
       (a :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f b, PBoring b,
 PSubcategory (PConst a) a) =>
Term s ((a :--> f b) :--> (PConst a a :--> f b))
ptraverse_ = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$
    forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (a :--> f b)
_ Term s (PConst a a)
_ ->
      forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f a) =>
Term s (a :--> f a)
ppure forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall (a :: S -> Type) (s :: S). PBoring a => Term s a
pboring

-- | @since 1.0.0
instance PTraversable PMaybe where
  ptraverse :: forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f a, PSubcategory f b,
 PSubcategory f (PMaybe b), PSubcategory PMaybe a,
 PSubcategory PMaybe b) =>
Term s ((a :--> f b) :--> (PMaybe a :--> f (PMaybe b)))
ptraverse = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$
    forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (a :--> f b)
f Term s (PMaybe a)
t -> forall (a :: S -> Type) (s :: S). TermCont s (Term s a) -> Term s a
unTermCont forall a b. (a -> b) -> a -> b
$ do
      PMaybe a s
t' <- forall {r :: S -> Type} (a :: S -> Type) (s :: S).
PlutusType a =>
Term s a -> TermCont s (a s)
pmatchC Term s (PMaybe a)
t
      forall (f :: Type -> Type) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ case PMaybe a s
t' of
        PMaybe a s
PNothing -> forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f a) =>
Term s (a :--> f a)
ppure forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon forall (a :: S -> Type) (s :: S). PMaybe a s
PNothing
        PJust Term s a
x -> forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PFunctor f, PSubcategory f a, PSubcategory f b) =>
Term s ((a :--> b) :--> (f a :--> f b))
pfmap forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam (forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: S -> Type) (s :: S). Term s a -> PMaybe a s
PJust) forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# (Term s (a :--> f b)
f forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s a
x)
  ptraverse_ :: forall (b :: S -> Type) (f :: (S -> Type) -> S -> Type)
       (a :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f b, PBoring b,
 PSubcategory PMaybe a) =>
Term s ((a :--> f b) :--> (PMaybe a :--> f b))
ptraverse_ = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$
    forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (a :--> f b)
f Term s (PMaybe a)
t -> forall (a :: S -> Type) (s :: S). TermCont s (Term s a) -> Term s a
unTermCont forall a b. (a -> b) -> a -> b
$ do
      PMaybe a s
t' <- forall {r :: S -> Type} (a :: S -> Type) (s :: S).
PlutusType a =>
Term s a -> TermCont s (a s)
pmatchC Term s (PMaybe a)
t
      forall (f :: Type -> Type) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ case PMaybe a s
t' of
        PMaybe a s
PNothing -> forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f a) =>
Term s (a :--> f a)
ppure forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall (a :: S -> Type) (s :: S). PBoring a => Term s a
pboring
        PJust Term s a
x -> Term s (a :--> f b)
f forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s a
x

-- | @since 1.0.0
instance PTraversable PMaybeData where
  ptraverse :: forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f a, PSubcategory f b,
 PSubcategory f (PMaybeData b), PSubcategory PMaybeData a,
 PSubcategory PMaybeData b) =>
Term s ((a :--> f b) :--> (PMaybeData a :--> f (PMaybeData b)))
ptraverse = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$
    forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (a :--> f b)
f Term s (PMaybeData a)
t -> forall (a :: S -> Type) (s :: S). TermCont s (Term s a) -> Term s a
unTermCont forall a b. (a -> b) -> a -> b
$ do
      PMaybeData a s
t' <- forall {r :: S -> Type} (a :: S -> Type) (s :: S).
PlutusType a =>
Term s a -> TermCont s (a s)
pmatchC Term s (PMaybeData a)
t
      forall (f :: Type -> Type) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ case PMaybeData a s
t' of
        PDNothing Term s (PDataRecord '[])
_ -> forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f a) =>
Term s (a :--> f a)
ppure forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# (forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: S -> Type) (s :: S).
Term s (PDataRecord '[]) -> PMaybeData a s
PDNothing forall a b. (a -> b) -> a -> b
$ forall (s :: S). Term s (PDataRecord '[])
pdnil)
        PDJust Term s (PDataRecord '[ "_0" ':= a])
t'' ->
          let res :: Term s (f b)
res = Term s (a :--> f b)
f forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData (forall (name :: Symbol) (b :: S -> Type) (p :: S -> Type) (s :: S)
       (a :: S -> Type) (as :: [PLabeledType]) (n :: Nat).
(PDataFields p, as ~ PFields p, n ~ PLabelIndex name as,
 KnownNat n, a ~ PUnLabel (IndexList n as), PFromDataable a b) =>
Term s (p :--> b)
pfield @"_0" forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s (PDataRecord '[ "_0" ':= a])
t'')
           in forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PFunctor f, PSubcategory f a, PSubcategory f b) =>
Term s ((a :--> b) :--> (f a :--> f b))
pfmap forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam (\Term s b
y -> forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: S -> Type) (s :: S).
Term s (PDataRecord '[ "_0" ':= a]) -> PMaybeData a s
PDJust forall a b. (a -> b) -> a -> b
$ forall (label :: Symbol) (a :: S -> Type) (l :: [PLabeledType])
       (s :: S).
Term
  s
  (PAsData a
   :--> (PDataRecord l :--> PDataRecord ((label ':= a) : l)))
pdcons forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s a -> Term s (PAsData a)
pdata Term s b
y forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall (s :: S). Term s (PDataRecord '[])
pdnil) forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s (f b)
res
  ptraverse_ :: forall (b :: S -> Type) (f :: (S -> Type) -> S -> Type)
       (a :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f b, PBoring b,
 PSubcategory PMaybeData a) =>
Term s ((a :--> f b) :--> (PMaybeData a :--> f b))
ptraverse_ = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$
    forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (a :--> f b)
f Term s (PMaybeData a)
t -> forall (a :: S -> Type) (s :: S). TermCont s (Term s a) -> Term s a
unTermCont forall a b. (a -> b) -> a -> b
$ do
      PMaybeData a s
t' <- forall {r :: S -> Type} (a :: S -> Type) (s :: S).
PlutusType a =>
Term s a -> TermCont s (a s)
pmatchC Term s (PMaybeData a)
t
      forall (f :: Type -> Type) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ case PMaybeData a s
t' of
        PDNothing Term s (PDataRecord '[])
_ -> forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f a) =>
Term s (a :--> f a)
ppure forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall (a :: S -> Type) (s :: S). PBoring a => Term s a
pboring
        PDJust Term s (PDataRecord '[ "_0" ':= a])
t'' -> Term s (a :--> f b)
f forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall (a :: S -> Type) (s :: S).
PIsData a =>
Term s (PAsData a) -> Term s a
pfromData (forall (name :: Symbol) (b :: S -> Type) (p :: S -> Type) (s :: S)
       (a :: S -> Type) (as :: [PLabeledType]) (n :: Nat).
(PDataFields p, as ~ PFields p, n ~ PLabelIndex name as,
 KnownNat n, a ~ PUnLabel (IndexList n as), PFromDataable a b) =>
Term s (p :--> b)
pfield @"_0" forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s (PDataRecord '[ "_0" ':= a])
t'')

-- | @since 1.0.0
instance PTraversable PList where
  ptraverse :: forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f a, PSubcategory f b,
 PSubcategory f (PList b), PSubcategory PList a,
 PSubcategory PList b) =>
Term s ((a :--> f b) :--> (PList a :--> f (PList b)))
ptraverse = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic
    forall a b. (a -> b) -> a -> b
$ forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (((a :--> b) :--> (a :--> b)) :--> (a :--> b))
pfix
      #$ plam
    $ \self f xs ->
      pmatch (puncons # xs) $ \case
        PNothing -> ppure # pnil
        PJust t' -> do
          pmatch t' $ \case
            PPair thead ttail ->
              pliftA2 # pcons # (f # thead) # (self # f # ttail)
  ptraverse_ ::
    forall
      (b :: S -> Type)
      (f :: (S -> Type) -> S -> Type)
      (a :: S -> Type)
      (s :: S).
    ( PApplicative f
    , PSubcategory f b
    , PBoring b
    ) =>
    Term s ((a :--> f b) :--> PList a :--> f b)
  ptraverse_ :: forall (b :: S -> Type) (f :: (S -> Type) -> S -> Type)
       (a :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f b, PBoring b) =>
Term s ((a :--> f b) :--> (PList a :--> f b))
ptraverse_ = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$ forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (((a :--> b) :--> (a :--> b)) :--> (a :--> b))
pfix forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
#$ forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ forall (s' :: S).
Term s' ((a :--> f b) :--> (PList a :--> f b))
-> Term s' (a :--> f b) -> Term s' (PList a) -> Term s' (f b)
go
    where
      go ::
        forall (s' :: S).
        Term s' ((a :--> f b) :--> PList a :--> f b) ->
        Term s' (a :--> f b) ->
        Term s' (PList a) ->
        Term s' (f b)
      go :: forall (s' :: S).
Term s' ((a :--> f b) :--> (PList a :--> f b))
-> Term s' (a :--> f b) -> Term s' (PList a) -> Term s' (f b)
go Term s' ((a :--> f b) :--> (PList a :--> f b))
self Term s' (a :--> f b)
f Term s' (PList a)
xs = forall (a :: S -> Type) (s :: S). TermCont s (Term s a) -> Term s a
unTermCont forall a b. (a -> b) -> a -> b
$ do
        PMaybe (PPair a (PList a)) s'
t <- forall {r :: S -> Type} (a :: S -> Type) (s :: S).
PlutusType a =>
Term s a -> TermCont s (a s)
pmatchC (forall (list :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (s :: S).
PIsListLike list a =>
Term s (list a :--> PMaybe (PPair a (list a)))
puncons forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s' (PList a)
xs)
        case PMaybe (PPair a (PList a)) s'
t of
          PMaybe (PPair a (PList a)) s'
PNothing -> forall (f :: Type -> Type) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f a) =>
Term s (a :--> f a)
ppure forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall (a :: S -> Type) (s :: S). PBoring a => Term s a
pboring
          PJust Term s' (PPair a (PList a))
t' -> do
            PPair Term s' a
thead Term s' (PList a)
ttail <- forall {r :: S -> Type} (a :: S -> Type) (s :: S).
PlutusType a =>
Term s a -> TermCont s (a s)
pmatchC Term s' (PPair a (PList a))
t'
            forall (f :: Type -> Type) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ (Term s' (a :--> f b)
f forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s' a
thead) forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PSubcategory f a, PSubcategory f b, PApply f) =>
Term s (f a) -> Term s (f b) -> Term s (f b)
#*> (Term s' ((a :--> f b) :--> (PList a :--> f b))
self forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s' (a :--> f b)
f forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s' (PList a)
ttail)

-- | @since 1.0.0
instance PTraversable PBuiltinList where
  ptraverse :: forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f a, PSubcategory f b,
 PSubcategory f (PBuiltinList b), PSubcategory PBuiltinList a,
 PSubcategory PBuiltinList b) =>
Term s ((a :--> f b) :--> (PBuiltinList a :--> f (PBuiltinList b)))
ptraverse = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic
    forall a b. (a -> b) -> a -> b
$ forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (((a :--> b) :--> (a :--> b)) :--> (a :--> b))
pfix
      #$ plam
    $ \r f xs ->
      pmatch (puncons # xs) $ \case
        PNothing -> ppure # pnil
        PJust t' -> do
          pmatch t' $ \case
            PPair thead ttail ->
              pliftA2 # pcons # (f # thead) # (r # f # ttail)
  ptraverse_ ::
    forall
      (b :: S -> Type)
      (f :: (S -> Type) -> S -> Type)
      (a :: S -> Type)
      (s :: S).
    ( PApplicative f
    , PSubcategory f b
    , PBoring b
    , PSubcategory PBuiltinList a
    ) =>
    Term s ((a :--> f b) :--> PBuiltinList a :--> f b)
  ptraverse_ :: forall (b :: S -> Type) (f :: (S -> Type) -> S -> Type)
       (a :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f b, PBoring b,
 PSubcategory PBuiltinList a) =>
Term s ((a :--> f b) :--> (PBuiltinList a :--> f b))
ptraverse_ = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$ forall (s :: S) (a :: S -> Type) (b :: S -> Type).
Term s (((a :--> b) :--> (a :--> b)) :--> (a :--> b))
pfix forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
#$ forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ forall (s' :: S).
Term s' ((a :--> f b) :--> (PBuiltinList a :--> f b))
-> Term s' (a :--> f b)
-> Term s' (PBuiltinList a)
-> Term s' (f b)
go
    where
      go ::
        forall (s' :: S).
        Term s' ((a :--> f b) :--> PBuiltinList a :--> f b) ->
        Term s' (a :--> f b) ->
        Term s' (PBuiltinList a) ->
        Term s' (f b)
      go :: forall (s' :: S).
Term s' ((a :--> f b) :--> (PBuiltinList a :--> f b))
-> Term s' (a :--> f b)
-> Term s' (PBuiltinList a)
-> Term s' (f b)
go Term s' ((a :--> f b) :--> (PBuiltinList a :--> f b))
self Term s' (a :--> f b)
f Term s' (PBuiltinList a)
xs = forall (a :: S -> Type) (s :: S). TermCont s (Term s a) -> Term s a
unTermCont forall a b. (a -> b) -> a -> b
$ do
        PMaybe (PPair a (PBuiltinList a)) s'
t <- forall {r :: S -> Type} (a :: S -> Type) (s :: S).
PlutusType a =>
Term s a -> TermCont s (a s)
pmatchC (forall (list :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (s :: S).
PIsListLike list a =>
Term s (list a :--> PMaybe (PPair a (list a)))
puncons forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s' (PBuiltinList a)
xs)
        case PMaybe (PPair a (PBuiltinList a)) s'
t of
          PMaybe (PPair a (PBuiltinList a)) s'
PNothing -> forall (f :: Type -> Type) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f a) =>
Term s (a :--> f a)
ppure forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall (a :: S -> Type) (s :: S). PBoring a => Term s a
pboring
          PJust Term s' (PPair a (PBuiltinList a))
t' -> do
            PPair Term s' a
thead Term s' (PBuiltinList a)
ttail <- forall {r :: S -> Type} (a :: S -> Type) (s :: S).
PlutusType a =>
Term s a -> TermCont s (a s)
pmatchC Term s' (PPair a (PBuiltinList a))
t'
            forall (f :: Type -> Type) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ (Term s' (a :--> f b)
f forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s' a
thead) forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PSubcategory f a, PSubcategory f b, PApply f) =>
Term s (f a) -> Term s (f b) -> Term s (f b)
#*> (Term s' ((a :--> f b) :--> (PBuiltinList a :--> f b))
self forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s' (a :--> f b)
f forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s' (PBuiltinList a)
ttail)

-- | @since 1.0.0
instance PTraversable (PPair a) where
  ptraverse :: forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f a, PSubcategory f b,
 PSubcategory f (PPair a b), PSubcategory (PPair a) a,
 PSubcategory (PPair a) b) =>
Term s ((a :--> f b) :--> (PPair a a :--> f (PPair a b)))
ptraverse = forall (t :: (S -> Type) -> S -> Type)
       (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (b :: S -> Type)
       (s :: S).
(PSemiTraversable t, PApply f, PSubcategory f a, PSubcategory f b,
 PSubcategory f (t b)) =>
Term s ((a :--> f b) :--> (t a :--> f (t b)))
psemitraverse
  ptraverse_ :: forall (b :: S -> Type) (f :: (S -> Type) -> S -> Type)
       (a :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f b, PBoring b,
 PSubcategory (PPair a) a) =>
Term s ((a :--> f b) :--> (PPair a a :--> f b))
ptraverse_ = forall (t :: (S -> Type) -> S -> Type) (b :: S -> Type)
       (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PSemiTraversable t, PApply f, PSubcategory f b, PBoring b,
 PSubcategory t a) =>
Term s ((a :--> f b) :--> (t a :--> f b))
psemitraverse_

-- | @since 1.0.0
instance PTraversable (PEither e) where
  ptraverse :: forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f a, PSubcategory f b,
 PSubcategory f (PEither e b), PSubcategory (PEither e) a,
 PSubcategory (PEither e) b) =>
Term s ((a :--> f b) :--> (PEither e a :--> f (PEither e b)))
ptraverse = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$
    forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (a :--> f b)
f Term s (PEither e a)
t -> forall (a :: S -> Type) (s :: S). TermCont s (Term s a) -> Term s a
unTermCont forall a b. (a -> b) -> a -> b
$ do
      PEither e a s
t' <- forall {r :: S -> Type} (a :: S -> Type) (s :: S).
PlutusType a =>
Term s a -> TermCont s (a s)
pmatchC Term s (PEither e a)
t
      forall (f :: Type -> Type) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ case PEither e a s
t' of
        PLeft Term s e
e -> forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f a) =>
Term s (a :--> f a)
ppure forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# (forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: S -> Type) (b :: S -> Type) (s :: S).
Term s a -> PEither a b s
PLeft forall a b. (a -> b) -> a -> b
$ Term s e
e)
        PRight Term s a
x -> forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PFunctor f, PSubcategory f a, PSubcategory f b) =>
Term s ((a :--> b) :--> (f a :--> f b))
pfmap forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam (forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: S -> Type) (b :: S -> Type) (s :: S).
Term s b -> PEither a b s
PRight) forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# (Term s (a :--> f b)
f forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s a
x)
  ptraverse_ :: forall (b :: S -> Type) (f :: (S -> Type) -> S -> Type)
       (a :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f b, PBoring b,
 PSubcategory (PEither e) a) =>
Term s ((a :--> f b) :--> (PEither e a :--> f b))
ptraverse_ = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$
    forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (a :--> f b)
f Term s (PEither e a)
t -> forall (a :: S -> Type) (s :: S). TermCont s (Term s a) -> Term s a
unTermCont forall a b. (a -> b) -> a -> b
$ do
      PEither e a s
t' <- forall {r :: S -> Type} (a :: S -> Type) (s :: S).
PlutusType a =>
Term s a -> TermCont s (a s)
pmatchC Term s (PEither e a)
t
      forall (f :: Type -> Type) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ case PEither e a s
t' of
        PLeft Term s e
_ -> forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f a) =>
Term s (a :--> f a)
ppure forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall (a :: S -> Type) (s :: S). PBoring a => Term s a
pboring
        PRight Term s a
x -> Term s (a :--> f b)
f forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s a
x

-- | @since 1.0.0
class (PTraversable t) => PSemiTraversable (t :: (S -> Type) -> S -> Type) where
  psemitraverse ::
    forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (b :: S -> Type) (s :: S).
    ( PApply f
    , PSubcategory f a
    , PSubcategory f b
    , PSubcategory f (t b)
    ) =>
    Term s ((a :--> f b) :--> t a :--> f (t b))

  -- Similar to 'ptraverse_', but only requiring an 'Apply'.
  --
  -- @since 1.2.0
  psemitraverse_ ::
    forall
      (b :: S -> Type)
      (f :: (S -> Type) -> S -> Type)
      (a :: S -> Type)
      (s :: S).
    ( PApply f
    , PSubcategory f b
    , PBoring b
    , PSubcategory t a
    ) =>
    Term s ((a :--> f b) :--> t a :--> f b)

-- | @since 1.0.0
instance PSemiTraversable PIdentity where
  psemitraverse :: forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PApply f, PSubcategory f a, PSubcategory f b,
 PSubcategory f (PIdentity b)) =>
Term s ((a :--> f b) :--> (PIdentity a :--> f (PIdentity b)))
psemitraverse = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$
    forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (a :--> f b)
f Term s (PIdentity a)
t -> forall (a :: S -> Type) (s :: S). TermCont s (Term s a) -> Term s a
unTermCont forall a b. (a -> b) -> a -> b
$ do
      PIdentity Term s a
tx <- forall {r :: S -> Type} (a :: S -> Type) (s :: S).
PlutusType a =>
Term s a -> TermCont s (a s)
pmatchC Term s (PIdentity a)
t
      forall (f :: Type -> Type) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PFunctor f, PSubcategory f a, PSubcategory f b) =>
Term s ((a :--> b) :--> (f a :--> f b))
pfmap forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f a) =>
Term s (a :--> f a)
ppure forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# (Term s (a :--> f b)
f forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s a
tx)
  psemitraverse_ :: forall (b :: S -> Type) (f :: (S -> Type) -> S -> Type)
       (a :: S -> Type) (s :: S).
(PApply f, PSubcategory f b, PBoring b,
 PSubcategory PIdentity a) =>
Term s ((a :--> f b) :--> (PIdentity a :--> f b))
psemitraverse_ = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$ forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (a :--> f b)
f Term s (PIdentity a)
t -> Term s (a :--> f b)
f forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# (forall (w :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PComonad w, PSubcategory w a) =>
Term s (w a :--> a)
pextract forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s (PIdentity a)
t)

-- | @since 1.0.0
instance PSemiTraversable PSum where
  psemitraverse :: forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PApply f, PSubcategory f a, PSubcategory f b,
 PSubcategory f (PSum b)) =>
Term s ((a :--> f b) :--> (PSum a :--> f (PSum b)))
psemitraverse = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$
    forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (a :--> f b)
f Term s (PSum a)
t -> forall (a :: S -> Type) (s :: S). TermCont s (Term s a) -> Term s a
unTermCont forall a b. (a -> b) -> a -> b
$ do
      PSum Term s a
tx <- forall {r :: S -> Type} (a :: S -> Type) (s :: S).
PlutusType a =>
Term s a -> TermCont s (a s)
pmatchC Term s (PSum a)
t
      forall (f :: Type -> Type) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PFunctor f, PSubcategory f a, PSubcategory f b) =>
Term s ((a :--> b) :--> (f a :--> f b))
pfmap forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PApplicative f, PSubcategory f a) =>
Term s (a :--> f a)
ppure forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# (Term s (a :--> f b)
f forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s a
tx)
  psemitraverse_ :: forall (b :: S -> Type) (f :: (S -> Type) -> S -> Type)
       (a :: S -> Type) (s :: S).
(PApply f, PSubcategory f b, PBoring b, PSubcategory PSum a) =>
Term s ((a :--> f b) :--> (PSum a :--> f b))
psemitraverse_ = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$ forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (a :--> f b)
f Term s (PSum a)
t -> Term s (a :--> f b)
f forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# (forall (w :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PComonad w, PSubcategory w a) =>
Term s (w a :--> a)
pextract forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s (PSum a)
t)

-- | @since 1.0.0
instance PSemiTraversable (PPair a) where
  psemitraverse :: forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PApply f, PSubcategory f a, PSubcategory f b,
 PSubcategory f (PPair a b)) =>
Term s ((a :--> f b) :--> (PPair a a :--> f (PPair a b)))
psemitraverse = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$
    forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (a :--> f b)
f Term s (PPair a a)
t -> forall (a :: S -> Type) (s :: S). TermCont s (Term s a) -> Term s a
unTermCont forall a b. (a -> b) -> a -> b
$ do
      PPair Term s a
x Term s a
y <- forall {r :: S -> Type} (a :: S -> Type) (s :: S).
PlutusType a =>
Term s a -> TermCont s (a s)
pmatchC Term s (PPair a a)
t
      Term s (f b)
res <- forall {r :: S -> Type} (s :: S) (a :: S -> Type).
Term s a -> TermCont s (Term s a)
pletC (Term s (a :--> f b)
f forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s a
y)
      forall (f :: Type -> Type) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ forall (f :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PFunctor f, PSubcategory f a, PSubcategory f b) =>
Term s ((a :--> b) :--> (f a :--> f b))
pfmap forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam (forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: S -> Type) (b :: S -> Type) (s :: S).
Term s a -> Term s b -> PPair a b s
PPair Term s a
x) forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s (f b)
res
  psemitraverse_ :: forall (b :: S -> Type) (f :: (S -> Type) -> S -> Type)
       (a :: S -> Type) (s :: S).
(PApply f, PSubcategory f b, PBoring b,
 PSubcategory (PPair a) a) =>
Term s ((a :--> f b) :--> (PPair a a :--> f b))
psemitraverse_ = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$
    forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (a :--> f b)
f Term s (PPair a a)
t -> forall (a :: S -> Type) (s :: S). TermCont s (Term s a) -> Term s a
unTermCont forall a b. (a -> b) -> a -> b
$ do
      PPair Term s a
_ Term s a
ty <- forall {r :: S -> Type} (a :: S -> Type) (s :: S).
PlutusType a =>
Term s a -> TermCont s (a s)
pmatchC Term s (PPair a a)
t
      forall (f :: Type -> Type) a. Applicative f => a -> f a
pure forall a b. (a -> b) -> a -> b
$ Term s (a :--> f b)
f forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s a
ty

{- | Collapse a non-empty \'structure\' full of a 'Semigroup'.

 @since 1.2.0
-}
psemifold ::
  forall
    (t :: (S -> Type) -> S -> Type)
    (a :: S -> Type)
    (s :: S).
  ( PSemiTraversable t
  , forall (s' :: S). Semigroup (Term s' a)
  , PSubcategory t a
  ) =>
  Term s (t a :--> a)
psemifold :: forall (t :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PSemiTraversable t, forall (s' :: S). Semigroup (Term s' a),
 PSubcategory t a) =>
Term s (t a :--> a)
psemifold = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$
  forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (t a)
t -> forall (a :: S -> Type) (s :: S). TermCont s (Term s a) -> Term s a
unTermCont forall a b. (a -> b) -> a -> b
$ do
    PConst Term s a
res <- forall {r :: S -> Type} (a :: S -> Type) (s :: S).
PlutusType a =>
Term s a -> TermCont s (a s)
pmatchC (forall (t :: (S -> Type) -> S -> Type) (b :: S -> Type)
       (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PSemiTraversable t, PApply f, PSubcategory f b, PBoring b,
 PSubcategory t a) =>
Term s ((a :--> f b) :--> (t a :--> f b))
psemitraverse_ forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall (s' :: S). Term s' (a :--> PConst a PUnit)
go forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s (t a)
t)
    forall (f :: Type -> Type) a. Applicative f => a -> f a
pure Term s a
res
  where
    go :: forall (s' :: S). Term s' (a :--> PConst a PUnit)
    go :: forall (s' :: S). Term s' (a :--> PConst a PUnit)
go = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$ forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: S -> Type) (b :: S -> Type) (s :: S).
Term s a -> PConst a b s
PConst

{- | Collapse a non-empty \'structure\' with a projection into a 'Semigroup'.

 @since 1.2.0
-}
psemifoldMap ::
  forall (t :: (S -> Type) -> S -> Type) (a :: S -> Type) (b :: S -> Type) (s :: S).
  (PSemiTraversable t, forall (s' :: S). Semigroup (Term s' b), PSubcategory t a) =>
  Term s ((a :--> b) :--> t a :--> b)
psemifoldMap :: forall (t :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PSemiTraversable t, forall (s' :: S). Semigroup (Term s' b),
 PSubcategory t a) =>
Term s ((a :--> b) :--> (t a :--> b))
psemifoldMap = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$
  forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (a :--> b)
f Term s (t a)
t -> forall (a :: S -> Type) (s :: S). TermCont s (Term s a) -> Term s a
unTermCont forall a b. (a -> b) -> a -> b
$ do
    PConst Term s b
res <- forall {r :: S -> Type} (a :: S -> Type) (s :: S).
PlutusType a =>
Term s a -> TermCont s (a s)
pmatchC (forall (t :: (S -> Type) -> S -> Type) (b :: S -> Type)
       (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PSemiTraversable t, PApply f, PSubcategory f b, PBoring b,
 PSubcategory t a) =>
Term s ((a :--> f b) :--> (t a :--> f b))
psemitraverse_ forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# (forall (s' :: S). Term s' ((a :--> b) :--> (a :--> PConst b PUnit))
go forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s (a :--> b)
f) forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s (t a)
t)
    forall (f :: Type -> Type) a. Applicative f => a -> f a
pure Term s b
res
  where
    go ::
      forall (s' :: S).
      Term s' ((a :--> b) :--> a :--> PConst b PUnit)
    go :: forall (s' :: S). Term s' ((a :--> b) :--> (a :--> PConst b PUnit))
go = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$ forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (a :--> b)
f Term s a
x -> forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: S -> Type) (b :: S -> Type) (s :: S).
Term s a -> PConst a b s
PConst forall a b. (a -> b) -> a -> b
$ Term s (a :--> b)
f forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s a
x

{- | Collapse a non-empty \'structure\' with a projection into a 'PComonad'.
 This is the most general semifold possible.

 @since 1.2.0
-}
psemifoldComonad ::
  forall
    (t :: (S -> Type) -> S -> Type)
    (f :: (S -> Type) -> S -> Type)
    (a :: S -> Type)
    (b :: S -> Type)
    (s :: S).
  ( PComonad f
  , PSemiTraversable t
  , forall (s' :: S). Semigroup (Term s' (f b))
  , PSubcategory f b
  , PSubcategory t a
  ) =>
  Term s ((a :--> f b) :--> t a :--> b)
psemifoldComonad :: forall (t :: (S -> Type) -> S -> Type)
       (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (b :: S -> Type)
       (s :: S).
(PComonad f, PSemiTraversable t,
 forall (s' :: S). Semigroup (Term s' (f b)), PSubcategory f b,
 PSubcategory t a) =>
Term s ((a :--> f b) :--> (t a :--> b))
psemifoldComonad = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$ forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (a :--> f b)
f Term s (t a)
t -> forall (w :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PComonad w, PSubcategory w a) =>
Term s (w a :--> a)
pextract forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# (forall (t :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PSemiTraversable t, forall (s' :: S). Semigroup (Term s' b),
 PSubcategory t a) =>
Term s ((a :--> b) :--> (t a :--> b))
psemifoldMap forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s (a :--> f b)
f forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s (t a)
t)

{- | Collapse a possibly empty \'structure\' full of a 'Monoid'.

 @since 1.0.0
-}
pfold ::
  forall (t :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
  ( PTraversable t
  , forall (s' :: S). Monoid (Term s' a)
  , PSubcategory t a
  ) =>
  Term s (t a :--> a)
pfold :: forall (t :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PTraversable t, forall (s' :: S). Monoid (Term s' a),
 PSubcategory t a) =>
Term s (t a :--> a)
pfold = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$
  forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (t a)
t -> forall (a :: S -> Type) (s :: S). TermCont s (Term s a) -> Term s a
unTermCont forall a b. (a -> b) -> a -> b
$ do
    PConst Term s a
res <- forall {r :: S -> Type} (a :: S -> Type) (s :: S).
PlutusType a =>
Term s a -> TermCont s (a s)
pmatchC (forall (t :: (S -> Type) -> S -> Type) (b :: S -> Type)
       (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PTraversable t, PApplicative f, PSubcategory f b, PBoring b,
 PSubcategory t a) =>
Term s ((a :--> f b) :--> (t a :--> f b))
ptraverse_ forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall (s' :: S). Term s' (a :--> PConst a PUnit)
go forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s (t a)
t)
    forall (f :: Type -> Type) a. Applicative f => a -> f a
pure Term s a
res
  where
    go ::
      forall (s' :: S).
      Term s' (a :--> PConst a PUnit)
    go :: forall (s' :: S). Term s' (a :--> PConst a PUnit)
go = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$ forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: S -> Type) (b :: S -> Type) (s :: S).
Term s a -> PConst a b s
PConst

{- | Collapse a possibly empty \'structure\' with a projection into a 'Monoid'.

 @since 1.0.0
-}
pfoldMap ::
  forall (t :: (S -> Type) -> S -> Type) (a :: S -> Type) (b :: S -> Type) (s :: S).
  ( PTraversable t
  , forall (s' :: S). Monoid (Term s' b)
  , PSubcategory t a
  ) =>
  Term s ((a :--> b) :--> t a :--> b)
pfoldMap :: forall (t :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PTraversable t, forall (s' :: S). Monoid (Term s' b),
 PSubcategory t a) =>
Term s ((a :--> b) :--> (t a :--> b))
pfoldMap = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$
  forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (a :--> b)
f Term s (t a)
t -> forall (a :: S -> Type) (s :: S). TermCont s (Term s a) -> Term s a
unTermCont forall a b. (a -> b) -> a -> b
$ do
    PConst Term s b
res <- forall {r :: S -> Type} (a :: S -> Type) (s :: S).
PlutusType a =>
Term s a -> TermCont s (a s)
pmatchC (forall (t :: (S -> Type) -> S -> Type) (b :: S -> Type)
       (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PTraversable t, PApplicative f, PSubcategory f b, PBoring b,
 PSubcategory t a) =>
Term s ((a :--> f b) :--> (t a :--> f b))
ptraverse_ forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# (forall (s' :: S). Term s' ((a :--> b) :--> (a :--> PConst b PUnit))
go forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s (a :--> b)
f) forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s (t a)
t)
    forall (f :: Type -> Type) a. Applicative f => a -> f a
pure Term s b
res
  where
    go ::
      forall (s' :: S).
      Term s' ((a :--> b) :--> a :--> PConst b PUnit)
    go :: forall (s' :: S). Term s' ((a :--> b) :--> (a :--> PConst b PUnit))
go = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$ forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (a :--> b)
f Term s a
x -> forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: S -> Type) (b :: S -> Type) (s :: S).
Term s a -> PConst a b s
PConst forall a b. (a -> b) -> a -> b
$ Term s (a :--> b)
f forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s a
x

{- | Collapse a possibly empty \'structure\' with a projection into a
 'PComonad'. This is the most general fold possible.

 @since 1.0.0
-}
pfoldComonad ::
  forall
    (t :: (S -> Type) -> S -> Type)
    (f :: (S -> Type) -> S -> Type)
    (a :: S -> Type)
    (b :: S -> Type)
    (s :: S).
  ( PComonad f
  , PTraversable t
  , forall (s' :: S). Monoid (Term s' (f b))
  , PSubcategory f b
  , PSubcategory t a
  ) =>
  Term s ((a :--> f b) :--> t a :--> b)
pfoldComonad :: forall (t :: (S -> Type) -> S -> Type)
       (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (b :: S -> Type)
       (s :: S).
(PComonad f, PTraversable t,
 forall (s' :: S). Monoid (Term s' (f b)), PSubcategory f b,
 PSubcategory t a) =>
Term s ((a :--> f b) :--> (t a :--> b))
pfoldComonad = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$ forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (a :--> f b)
f Term s (t a)
t -> forall (w :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PComonad w, PSubcategory w a) =>
Term s (w a :--> a)
pextract forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# (forall (t :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PTraversable t, forall (s' :: S). Monoid (Term s' b),
 PSubcategory t a) =>
Term s ((a :--> b) :--> (t a :--> b))
pfoldMap forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s (a :--> f b)
f forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s (t a)
t)

{- | Counts the number of elements in the \'structure\'.

 @since 1.0.0
-}
plength ::
  forall (t :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
  (PTraversable t, PSubcategory t a) =>
  Term s (t a :--> PInteger)
plength :: forall (t :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PTraversable t, PSubcategory t a) =>
Term s (t a :--> PInteger)
plength = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$ forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (t a)
t -> forall (t :: (S -> Type) -> S -> Type)
       (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (b :: S -> Type)
       (s :: S).
(PComonad f, PTraversable t,
 forall (s' :: S). Monoid (Term s' (f b)), PSubcategory f b,
 PSubcategory t a) =>
Term s ((a :--> f b) :--> (t a :--> b))
pfoldComonad forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall (s' :: S). Term s' (a :--> PSum PInteger)
go forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s (t a)
t
  where
    go ::
      forall (s' :: S).
      Term s' (a :--> PSum PInteger)
    go :: forall (s' :: S). Term s' (a :--> PSum PInteger)
go = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$ forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s a
_ -> forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: S -> Type) (s :: S). Term s a -> PSum a s
PSum forall a b. (a -> b) -> a -> b
$ Term s PInteger
1

{- | \'Add up\' all the elements in the structure.

 @since 1.0.0
-}
psum ::
  forall (t :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
  ( PTraversable t
  , PNum a
  , PSubcategory t a
  ) =>
  Term s (t a :--> a)
psum :: forall (t :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PTraversable t, PNum a, PSubcategory t a) =>
Term s (t a :--> a)
psum = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$ forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (t a)
t -> forall (t :: (S -> Type) -> S -> Type)
       (f :: (S -> Type) -> S -> Type) (a :: S -> Type) (b :: S -> Type)
       (s :: S).
(PComonad f, PTraversable t,
 forall (s' :: S). Monoid (Term s' (f b)), PSubcategory f b,
 PSubcategory t a) =>
Term s ((a :--> f b) :--> (t a :--> b))
pfoldComonad forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall (s' :: S). Term s' (a :--> PSum a)
go forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# Term s (t a)
t
  where
    go ::
      forall (s' :: S).
      Term s' (a :--> PSum a)
    go :: forall (s' :: S). Term s' (a :--> PSum a)
go = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$ forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (a :: S -> Type) (s :: S). Term s a -> PSum a s
PSum

-- | @since 1.3.0
pany ::
  forall (t :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
  (PTraversable t, PSubcategory t a) =>
  Term s ((a :--> PBool) :--> t a :--> PBool)
pany :: forall (t :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PTraversable t, PSubcategory t a) =>
Term s ((a :--> PBool) :--> (t a :--> PBool))
pany = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$
  forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (a :--> PBool)
f ->
    (forall (s :: S). Term s (PAny :--> PBool)
pgetAny forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
#)
      forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall (t :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PTraversable t, forall (s' :: S). Monoid (Term s' b),
 PSubcategory t a) =>
Term s ((a :--> b) :--> (t a :--> b))
pfoldMap forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam (forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (s :: S). Term s PBool -> PAny s
PAny forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Term s (a :--> PBool)
f forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
#)) forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
#)

-- | @since 1.3.0
pall ::
  forall (t :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
  (PTraversable t, PSubcategory t a) =>
  Term s ((a :--> PBool) :--> t a :--> PBool)
pall :: forall (t :: (S -> Type) -> S -> Type) (a :: S -> Type) (s :: S).
(PTraversable t, PSubcategory t a) =>
Term s ((a :--> PBool) :--> (t a :--> PBool))
pall = forall (a :: S -> Type) (s :: S).
HasCallStack =>
ClosedTerm a -> Term s a
phoistAcyclic forall a b. (a -> b) -> a -> b
$
  forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam forall a b. (a -> b) -> a -> b
$ \Term s (a :--> PBool)
f ->
    (forall (s :: S). Term s (PAll :--> PBool)
pgetAll forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
#)
      forall b c a. (b -> c) -> (a -> b) -> a -> c
. (forall (t :: (S -> Type) -> S -> Type) (a :: S -> Type)
       (b :: S -> Type) (s :: S).
(PTraversable t, forall (s' :: S). Monoid (Term s' b),
 PSubcategory t a) =>
Term s ((a :--> b) :--> (t a :--> b))
pfoldMap forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
# forall a (b :: S -> Type) (s :: S) (c :: S -> Type).
(PLamN a b s, HasCallStack) =>
(Term s c -> a) -> Term s (c :--> b)
plam (forall (a :: S -> Type) (s :: S). PlutusType a => a s -> Term s a
pcon forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (s :: S). Term s PBool -> PAll s
PAll forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Term s (a :--> PBool)
f forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
#)) forall (s :: S) (a :: S -> Type) (b :: S -> Type).
HasCallStack =>
Term s (a :--> b) -> Term s a -> Term s b
#)