module Plutarch.Extra.Script (applyArguments) where

import Control.Lens (over)
import Plutarch.Script (Script (Script))
import PlutusCore.Data qualified as PLC
import PlutusCore.MkPlc qualified as PLC
import UntypedPlutusCore qualified as UPLC

{- | Applys 'Data' to Script

 @since 3.20.0
-}
applyArguments :: Script -> [PLC.Data] -> Script
applyArguments :: Script -> [Data] -> Script
applyArguments (Script Program DeBruijn DefaultUni DefaultFun ()
p) [Data]
args =
  let termArgs :: [Term DeBruijn DefaultUni DefaultFun ()]
termArgs = forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a (uni :: Type -> Type) fun (term :: Type -> Type) tyname
       name ann.
(TermLike term tyname name uni fun, Includes uni a) =>
ann -> a -> term ann
PLC.mkConstant ()) [Data]
args
      applied :: Term DeBruijn DefaultUni DefaultFun ()
-> Term DeBruijn DefaultUni DefaultFun ()
applied Term DeBruijn DefaultUni DefaultFun ()
t = forall (term :: Type -> Type) tyname name (uni :: Type -> Type) fun
       ann.
TermLike term tyname name uni fun =>
ann -> term ann -> [term ann] -> term ann
PLC.mkIterApp () Term DeBruijn DefaultUni DefaultFun ()
t [Term DeBruijn DefaultUni DefaultFun ()]
termArgs
   in Program DeBruijn DefaultUni DefaultFun () -> Script
Script forall a b. (a -> b) -> a -> b
$ forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
over forall name1 (uni1 :: Type -> Type) fun1 ann name2
       (uni2 :: Type -> Type) fun2.
Lens
  (Program name1 uni1 fun1 ann)
  (Program name2 uni2 fun2 ann)
  (Term name1 uni1 fun1 ann)
  (Term name2 uni2 fun2 ann)
UPLC.progTerm Term DeBruijn DefaultUni DefaultFun ()
-> Term DeBruijn DefaultUni DefaultFun ()
applied Program DeBruijn DefaultUni DefaultFun ()
p