imports

module Plutarch.Docs.PList (pFe, pFeElim, pFeList) where
import Plutarch.Prelude

PList

Here's the Scott encoded cousin of PBuiltinList. What does that mean? Well, in practice, it just means that PList can contain any arbitrary term - not just builtin types. PList also has a PListLike instance - so you won't be missing any of those utilities here!

PList also has a PlutusType instance. You can construct a PList using pcon (but you should prefer using pcons from PListLike):

pFeList :: forall s. Term s (PList PByteString)
pFeList = pcon $ PSCons (phexByteStr "fe") $ pcon PSNil

would yield a PList PByteString with one element - 0xfe. Of course, you could have done that with pcons # phexByteStr "fe" # pnil instead!

You can also use pmatch to match on a list:

pFe :: forall s. Term s PString
pFe = pmatch (pcon $ PSCons (phexByteStr "fe") $ pcon PSNil) $ \case
  PSNil -> "hey hey there's nothing here!"
  PSCons _ _ -> "oooo fancy!"

But you should prefer pelimList from PListLike instead:

pFeElim :: forall s. Term s PString
pFeElim = pelimList (\_ _ -> "oooo fancy") "hey hey there's nothing here!" $ pcon $ PSCons (phexByteStr "fe") $ pcon PSNil