Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a Pad type, for user scratchpads.
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module UdonShell.Pad | ||
(Pad, insert, delete, lookup) | ||
where | ||
|
||
import Data.Typeable | ||
import Prelude hiding (lookup) | ||
import Udon.API | ||
import qualified Udon.DescCombinators as D | ||
import qualified Data.Map as Map | ||
|
||
newtype Pad = Pad { unPad :: Map.Map String DynRef } | ||
deriving (Typeable) | ||
|
||
conj f = Pad . f . unPad | ||
|
||
instance Data Pad where | ||
desc = D.wrap (Pad . Map.fromDistinctAscList, Map.toList . unPad) desc | ||
|
||
insert :: String -> DynRef -> Pad -> Pad | ||
insert str ref = conj (Map.insert str ref) | ||
|
||
delete :: String -> Pad -> Pad | ||
delete str = conj (Map.delete str) | ||
|
||
lookup :: Pad -> String -> Maybe DynRef | ||
lookup (Pad pad) str = Map.lookup str pad |