diff options
author | Julien Dessaux | 2023-07-19 11:56:17 +0200 |
---|---|---|
committer | Julien Dessaux | 2023-07-19 11:56:17 +0200 |
commit | 15a7d5bef97557fc0f8a7b3fe4a68bf84a807daa (patch) | |
tree | dbc19fceb7b4b6d7e7961a784b9da027bb65ff3f /haskell/src/SpaceTraders/Utils.hs | |
parent | [haskell] Refactored everything with a ReaderT pattern (diff) | |
download | spacetraders-15a7d5bef97557fc0f8a7b3fe4a68bf84a807daa.tar.gz spacetraders-15a7d5bef97557fc0f8a7b3fe4a68bf84a807daa.tar.bz2 spacetraders-15a7d5bef97557fc0f8a7b3fe4a68bf84a807daa.zip |
[haskell] refactoring
Diffstat (limited to 'haskell/src/SpaceTraders/Utils.hs')
-rw-r--r-- | haskell/src/SpaceTraders/Utils.hs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/haskell/src/SpaceTraders/Utils.hs b/haskell/src/SpaceTraders/Utils.hs new file mode 100644 index 0000000..12bfd6a --- /dev/null +++ b/haskell/src/SpaceTraders/Utils.hs @@ -0,0 +1,22 @@ +module SpaceTraders.Utils + ( decodeText + , fromJSONValue + , int2ByteString + ) where + +import Data.Aeson +import Data.Aeson.Types +import qualified Data.ByteString as B +import qualified Data.ByteString.Builder as B +import qualified Data.ByteString.Internal as B +import qualified Data.Text as T +import qualified Data.Text.Encoding as T + +decodeText :: FromJSON a => T.Text -> Maybe a +decodeText = decode . B.toLazyByteString . T.encodeUtf8Builder + +fromJSONValue :: FromJSON a => Value -> Either String a +fromJSONValue = parseEither parseJSON + +int2ByteString :: Int -> B.ByteString +int2ByteString = B.pack . map B.c2w . show |