module PlutusCore.FsTree
( FsTree (..)
, FolderContents (..)
, PlcEntity (..)
, PlcFsTree
, PlcFolderContents
, treeFolderContents
, plcTypeFile
, plcTermFile
, foldFsTree
, foldPlcFsTree
, foldPlcFolderContents
) where
import PlutusCore.Core
import PlutusCore.Name
data FsTree a
= FsFolder String (FolderContents a)
| FsFile String a
newtype FolderContents a = FolderContents
{ FolderContents a -> [FsTree a]
unFolderContents :: [FsTree a]
} deriving newtype (b -> FolderContents a -> FolderContents a
NonEmpty (FolderContents a) -> FolderContents a
FolderContents a -> FolderContents a -> FolderContents a
(FolderContents a -> FolderContents a -> FolderContents a)
-> (NonEmpty (FolderContents a) -> FolderContents a)
-> (forall b.
Integral b =>
b -> FolderContents a -> FolderContents a)
-> Semigroup (FolderContents a)
forall b. Integral b => b -> FolderContents a -> FolderContents a
forall a. NonEmpty (FolderContents a) -> FolderContents a
forall a. FolderContents a -> FolderContents a -> FolderContents a
forall a.
(a -> a -> a)
-> (NonEmpty a -> a)
-> (forall b. Integral b => b -> a -> a)
-> Semigroup a
forall a b. Integral b => b -> FolderContents a -> FolderContents a
stimes :: b -> FolderContents a -> FolderContents a
$cstimes :: forall a b. Integral b => b -> FolderContents a -> FolderContents a
sconcat :: NonEmpty (FolderContents a) -> FolderContents a
$csconcat :: forall a. NonEmpty (FolderContents a) -> FolderContents a
<> :: FolderContents a -> FolderContents a -> FolderContents a
$c<> :: forall a. FolderContents a -> FolderContents a -> FolderContents a
Semigroup, Semigroup (FolderContents a)
FolderContents a
Semigroup (FolderContents a)
-> FolderContents a
-> (FolderContents a -> FolderContents a -> FolderContents a)
-> ([FolderContents a] -> FolderContents a)
-> Monoid (FolderContents a)
[FolderContents a] -> FolderContents a
FolderContents a -> FolderContents a -> FolderContents a
forall a. Semigroup (FolderContents a)
forall a. FolderContents a
forall a.
Semigroup a -> a -> (a -> a -> a) -> ([a] -> a) -> Monoid a
forall a. [FolderContents a] -> FolderContents a
forall a. FolderContents a -> FolderContents a -> FolderContents a
mconcat :: [FolderContents a] -> FolderContents a
$cmconcat :: forall a. [FolderContents a] -> FolderContents a
mappend :: FolderContents a -> FolderContents a -> FolderContents a
$cmappend :: forall a. FolderContents a -> FolderContents a -> FolderContents a
mempty :: FolderContents a
$cmempty :: forall a. FolderContents a
$cp1Monoid :: forall a. Semigroup (FolderContents a)
Monoid)
data PlcEntity uni fun
= PlcType (Type TyName uni ())
| PlcTerm (Term TyName Name uni fun ())
type PlcFsTree uni fun = FsTree (PlcEntity uni fun)
type PlcFolderContents uni fun = FolderContents (PlcEntity uni fun)
treeFolderContents :: String -> [FsTree a] -> FsTree a
treeFolderContents :: String -> [FsTree a] -> FsTree a
treeFolderContents String
name = String -> FolderContents a -> FsTree a
forall a. String -> FolderContents a -> FsTree a
FsFolder String
name (FolderContents a -> FsTree a)
-> ([FsTree a] -> FolderContents a) -> [FsTree a] -> FsTree a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [FsTree a] -> FolderContents a
forall a. [FsTree a] -> FolderContents a
FolderContents
plcTypeFile :: String -> Type TyName uni () -> PlcFsTree uni fun
plcTypeFile :: String -> Type TyName uni () -> PlcFsTree uni fun
plcTypeFile String
name = String -> PlcEntity uni fun -> PlcFsTree uni fun
forall a. String -> a -> FsTree a
FsFile String
name (PlcEntity uni fun -> PlcFsTree uni fun)
-> (Type TyName uni () -> PlcEntity uni fun)
-> Type TyName uni ()
-> PlcFsTree uni fun
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Type TyName uni () -> PlcEntity uni fun
forall (uni :: * -> *) fun. Type TyName uni () -> PlcEntity uni fun
PlcType
plcTermFile :: String -> Term TyName Name uni fun () -> PlcFsTree uni fun
plcTermFile :: String -> Term TyName Name uni fun () -> PlcFsTree uni fun
plcTermFile String
name = String -> PlcEntity uni fun -> PlcFsTree uni fun
forall a. String -> a -> FsTree a
FsFile String
name (PlcEntity uni fun -> PlcFsTree uni fun)
-> (Term TyName Name uni fun () -> PlcEntity uni fun)
-> Term TyName Name uni fun ()
-> PlcFsTree uni fun
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Term TyName Name uni fun () -> PlcEntity uni fun
forall (uni :: * -> *) fun.
Term TyName Name uni fun () -> PlcEntity uni fun
PlcTerm
foldFsTree
:: (String -> [b] -> b)
-> (String -> a -> b)
-> FsTree a
-> b
foldFsTree :: (String -> [b] -> b) -> (String -> a -> b) -> FsTree a -> b
foldFsTree String -> [b] -> b
onFolder String -> a -> b
onFile = FsTree a -> b
go where
go :: FsTree a -> b
go (FsFolder String
name (FolderContents [FsTree a]
trees)) = String -> [b] -> b
onFolder String
name ([b] -> b) -> [b] -> b
forall a b. (a -> b) -> a -> b
$ (FsTree a -> b) -> [FsTree a] -> [b]
forall a b. (a -> b) -> [a] -> [b]
map FsTree a -> b
go [FsTree a]
trees
go (FsFile String
name a
x) = String -> a -> b
onFile String
name a
x
foldPlcFsTree
:: (String -> [b] -> b)
-> (String -> Type TyName uni () -> b)
-> (String -> Term TyName Name uni fun () -> b)
-> PlcFsTree uni fun
-> b
foldPlcFsTree :: (String -> [b] -> b)
-> (String -> Type TyName uni () -> b)
-> (String -> Term TyName Name uni fun () -> b)
-> PlcFsTree uni fun
-> b
foldPlcFsTree String -> [b] -> b
onFolder String -> Type TyName uni () -> b
onType String -> Term TyName Name uni fun () -> b
onTerm = (String -> [b] -> b)
-> (String -> PlcEntity uni fun -> b) -> PlcFsTree uni fun -> b
forall b a.
(String -> [b] -> b) -> (String -> a -> b) -> FsTree a -> b
foldFsTree String -> [b] -> b
onFolder String -> PlcEntity uni fun -> b
onFile where
onFile :: String -> PlcEntity uni fun -> b
onFile String
name (PlcType Type TyName uni ()
getTy) = String -> Type TyName uni () -> b
onType String
name Type TyName uni ()
getTy
onFile String
name (PlcTerm Term TyName Name uni fun ()
getTerm) = String -> Term TyName Name uni fun () -> b
onTerm String
name Term TyName Name uni fun ()
getTerm
foldPlcFolderContents
:: (String -> [b] -> b)
-> (String -> Type TyName uni () -> b)
-> (String -> Term TyName Name uni fun () -> b)
-> PlcFolderContents uni fun
-> [b]
foldPlcFolderContents :: (String -> [b] -> b)
-> (String -> Type TyName uni () -> b)
-> (String -> Term TyName Name uni fun () -> b)
-> PlcFolderContents uni fun
-> [b]
foldPlcFolderContents String -> [b] -> b
onFolder String -> Type TyName uni () -> b
onType String -> Term TyName Name uni fun () -> b
onTerm (FolderContents [FsTree (PlcEntity uni fun)]
trees) =
(FsTree (PlcEntity uni fun) -> b)
-> [FsTree (PlcEntity uni fun)] -> [b]
forall a b. (a -> b) -> [a] -> [b]
map ((String -> [b] -> b)
-> (String -> Type TyName uni () -> b)
-> (String -> Term TyName Name uni fun () -> b)
-> FsTree (PlcEntity uni fun)
-> b
forall b (uni :: * -> *) fun.
(String -> [b] -> b)
-> (String -> Type TyName uni () -> b)
-> (String -> Term TyName Name uni fun () -> b)
-> PlcFsTree uni fun
-> b
foldPlcFsTree String -> [b] -> b
onFolder String -> Type TyName uni () -> b
onType String -> Term TyName Name uni fun () -> b
onTerm) [FsTree (PlcEntity uni fun)]
trees