Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,7 @@
{-# language DeriveTraversable #-}
data Template a = Val a | List [Template a]
deriving ( Show
, Functor
, Foldable
, Traversable )

View file

@ -0,0 +1,2 @@
subst :: (Functor t, Eq i) => [(i,a)] -> t i -> t (Maybe a)
subst d = fmap (`lookup` d)

View file

@ -0,0 +1,2 @@
indexed :: [a] -> [(Int, a)]
indexed = zip [0..]

View file

@ -0,0 +1,7 @@
t :: Template Int
t = List [ List [Val 1, Val 2]
, List [Val 3, Val 4, Val 10]
, Val 5]
payloads :: [(Int, String)]
payloads = [(i, "payload#"++show i) | i <- [0..6]]

View file

@ -0,0 +1,7 @@
unusedIndices :: (Foldable t, Eq i) => [(i,a)] -> t i -> [i]
unusedIndices d = foldMap unused
where unused i = maybe (pure i) (pure []) $ lookup i d
unusedData :: (Foldable t, Eq i) => [(i, a)] -> t i -> [(i,a)]
unusedData = foldr delete
where delete i = filter ((i /= ) . fst)