summaryrefslogtreecommitdiff
path: root/Utility/Data.hs
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2024-03-19 19:47:48 +0800
committerSean Whitton <spwhitton@spwhitton.name>2024-03-19 19:47:48 +0800
commit4b47032686c52de5bf2324c1b1d4151c5fd6c41b (patch)
tree85098e25c0a4ad383f267fd59d591346d5e09a17 /Utility/Data.hs
parent34f99f9355c275917ff91539bbdac60a56ad7e17 (diff)
parent4993eab4a4507d52037ff74c67f6ca04d2401b5e (diff)
downloadgit-repair-4b47032686c52de5bf2324c1b1d4151c5fd6c41b.tar.gz
Merge tag '1.20230814'
tagging package git-repair version 1.20230814
Diffstat (limited to 'Utility/Data.hs')
-rw-r--r--Utility/Data.hs18
1 files changed, 17 insertions, 1 deletions
diff --git a/Utility/Data.hs b/Utility/Data.hs
index 5510845..faf9b34 100644
--- a/Utility/Data.hs
+++ b/Utility/Data.hs
@@ -1,6 +1,6 @@
{- utilities for simple data types
-
- - Copyright 2013 Joey Hess <id@joeyh.name>
+ - Copyright 2013-2021 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
@@ -10,8 +10,12 @@
module Utility.Data (
firstJust,
eitherToMaybe,
+ s2w8,
+ w82s,
) where
+import Data.Word
+
{- First item in the list that is not Nothing. -}
firstJust :: Eq a => [Maybe a] -> Maybe a
firstJust ms = case dropWhile (== Nothing) ms of
@@ -20,3 +24,15 @@ firstJust ms = case dropWhile (== Nothing) ms of
eitherToMaybe :: Either a b -> Maybe b
eitherToMaybe = either (const Nothing) Just
+
+c2w8 :: Char -> Word8
+c2w8 = fromIntegral . fromEnum
+
+w82c :: Word8 -> Char
+w82c = toEnum . fromIntegral
+
+s2w8 :: String -> [Word8]
+s2w8 = map c2w8
+
+w82s :: [Word8] -> String
+w82s = map w82c