Bits of optimisation

This commit is contained in:
Nox Sluijtman 2023-11-13 23:49:04 +01:00
parent 6d6bd045ad
commit 56b29314ad
3 changed files with 16 additions and 16 deletions

View file

@ -10,4 +10,4 @@ main = do
createExample testfile createExample testfile
sheet <- parseSheet testfile sheet <- parseSheet testfile
putStrLn $ "wrote example character named \"" ++ getName sheet ++ "\" to: " ++ testfile putStrLn $ "wrote example character named \"" ++ getName sheet ++ "\" to: " ++ testfile
listSkills sheet listSkillNames sheet

View file

@ -20,7 +20,6 @@
jailbreakUnbreak = pkg: jailbreakUnbreak = pkg:
pkgs.haskell.lib.doJailbreak (pkg.overrideAttrs (_: { meta = { }; })); pkgs.haskell.lib.doJailbreak (pkg.overrideAttrs (_: { meta = { }; }));
# DON'T FORGET TO PUT YOUR PACKAGE NAME HERE, REMOVING `throw`
packageName = "sheet-parser-hs"; packageName = "sheet-parser-hs";
in { in {
packages.${packageName} = packages.${packageName} =

View file

@ -1,32 +1,33 @@
module DND.Sheet.Parser module DND.Sheet.Parser
(getSheet ( parseSheet
, parseSheet --, getSheet
, listSkills , listSkills
, createExample , createExample
, getName , getName
, listSkillNames
) where ) where
import Data.Aeson import Data.Aeson
import DND.Sheet.Content import DND.Sheet.Content
import DND.Bob(bob) import DND.Bob(bob)
import Control.Monad
import qualified Data.ByteString.Lazy as B import qualified Data.ByteString.Lazy as B
import qualified Data.ByteString.Lazy.UTF8 as BSU import qualified Data.ByteString.Lazy.UTF8 as BSU
import Data.Maybe (fromJust) import Data.Maybe (fromJust)
getSheet :: FilePath -> IO B.ByteString --getSheet :: FilePath -> IO B.ByteString
getSheet = B.readFile --getSheet = B.readFile
parseSheet :: FilePath -> IO Character parseSheet :: FilePath -> IO Character
parseSheet x = do parseSheet x = unwrap . decode =<< B.readFile x
file <- B.readFile x where unwrap (Just y) = return y
let character = decode file :: Maybe Character unwrap Nothing = error $ "Failed to parse character sheet: " ++ x
return $ fromJust character
listSkills :: Character -> IO () listSkills :: Character -> [Skill]
listSkills = mapM_ (mapM_ putStrLn) listSkills = join . map skills . stats
. filter (not . null)
. map (map skillName . skills) listSkillNames :: Character -> IO ()
. stats listSkillNames = mapM_ (putStrLn . skillName) . listSkills
createExample :: FilePath -> IO () createExample :: FilePath -> IO ()
createExample = flip encodeFile bob createExample = flip encodeFile bob