summaryrefslogtreecommitdiffstats
path: root/src/Blessings
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-03-07 23:28:58 +0100
committertv <tv@krebsco.de>2026-03-08 04:01:23 +0100
commitae9f49e0a6e7d5a0c906d8e4fd153ad553cdecf1 (patch)
tree8dbb213f5796da9215742afa9d30682e3dcc5dd0 /src/Blessings
parenta6dd9834628614c0b7c815165bc0cf4139131b8c (diff)
use mono-traversable
Diffstat (limited to 'src/Blessings')
-rw-r--r--src/Blessings/ByteString.hs20
-rw-r--r--src/Blessings/ByteString/Lazy.hs20
-rw-r--r--src/Blessings/Internal.hs16
-rw-r--r--src/Blessings/String.hs21
-rw-r--r--src/Blessings/String/WCWidth.hs66
-rw-r--r--src/Blessings/Text.hs21
-rw-r--r--src/Blessings/Text/WCWidth.hs66
7 files changed, 0 insertions, 230 deletions
diff --git a/src/Blessings/ByteString.hs b/src/Blessings/ByteString.hs
deleted file mode 100644
index 4fe66cc..0000000
--- a/src/Blessings/ByteString.hs
+++ /dev/null
@@ -1,20 +0,0 @@
-{-# OPTIONS_GHC -fno-warn-orphans #-}
-
-module Blessings.ByteString
- ( module Blessings
- ) where
-
-import Blessings
-import Blessings.Internal
-import qualified Data.ByteString.Char8 as B
-
-
-instance Blessable B.ByteString where
- length = B.length
- drop = B.drop
- take = B.take
- splitAt = B.splitAt
- break = B.break
- intercalate = B.intercalate
- fromWord8 = B.pack . Prelude.show
- show = B.pack . Prelude.show
diff --git a/src/Blessings/ByteString/Lazy.hs b/src/Blessings/ByteString/Lazy.hs
deleted file mode 100644
index 23394b5..0000000
--- a/src/Blessings/ByteString/Lazy.hs
+++ /dev/null
@@ -1,20 +0,0 @@
-{-# OPTIONS_GHC -fno-warn-orphans #-}
-
-module Blessings.ByteString.Lazy
- ( module Blessings
- ) where
-
-import Blessings
-import Blessings.Internal
-import qualified Data.ByteString.Lazy.Char8 as L
-
-
-instance Blessable L.ByteString where
- length = fromIntegral . L.length
- drop = L.drop . fromIntegral
- take = L.take . fromIntegral
- splitAt = L.splitAt . fromIntegral
- break = L.break
- intercalate = L.intercalate
- fromWord8 = L.pack . Prelude.show
- show = L.pack . Prelude.show
diff --git a/src/Blessings/Internal.hs b/src/Blessings/Internal.hs
deleted file mode 100644
index 62d8fd4..0000000
--- a/src/Blessings/Internal.hs
+++ /dev/null
@@ -1,16 +0,0 @@
-{-# LANGUAGE ConstrainedClassMethods #-}
-module Blessings.Internal where
-
-import Data.String (IsString)
-import Data.Word (Word8)
-
-
-class (IsString a, Monoid a) => Blessable a where
- length :: a -> Int
- drop :: Int -> a -> a
- take :: Int -> a -> a
- splitAt :: Int -> a -> (a, a)
- break :: (Char -> Bool) -> a -> (a, a)
- intercalate :: a -> [a] -> a
- fromWord8 :: Word8 -> a
- show :: Show x => x -> a
diff --git a/src/Blessings/String.hs b/src/Blessings/String.hs
deleted file mode 100644
index 8dc6bcf..0000000
--- a/src/Blessings/String.hs
+++ /dev/null
@@ -1,21 +0,0 @@
-{-# LANGUAGE FlexibleInstances #-}
-{-# OPTIONS_GHC -fno-warn-orphans #-}
-
-module Blessings.String
- ( module Blessings
- ) where
-
-import Blessings
-import Blessings.Internal
-import qualified Data.List as L
-
-
-instance Blessable String where
- length = L.length
- drop = L.drop
- take = L.take
- splitAt = L.splitAt
- break = L.break
- intercalate = L.intercalate
- fromWord8 = Prelude.show
- show = Prelude.show
diff --git a/src/Blessings/String/WCWidth.hs b/src/Blessings/String/WCWidth.hs
deleted file mode 100644
index 16ab853..0000000
--- a/src/Blessings/String/WCWidth.hs
+++ /dev/null
@@ -1,66 +0,0 @@
-{-# LANGUAGE FlexibleInstances #-}
-{-# LANGUAGE ImportQualifiedPost #-}
-{-# LANGUAGE MultiWayIf #-}
-{-# LANGUAGE PatternGuards #-}
-{-# OPTIONS_GHC -fno-warn-orphans #-}
-module Blessings.String.WCWidth
- ( module Blessings
- ) where
-
-import Blessings
-import Blessings.Internal
-import Data.Char.WCWidth qualified as WCWidth
-import Data.List qualified as List
-
-
-instance Blessable String where
- length = length'
- drop = drop'
- take = take'
- splitAt = splitAt'
- break = List.break
- intercalate = List.intercalate
- fromWord8 = Prelude.show
- show = Prelude.show
-
-
-length' :: String -> Int
-length' = foldr ((+) . wcwidth') 0
-
-drop' :: Int -> String -> String
-drop' k t =
- if k <= 0
- then t
- else
- case t of
- c : t' ->
- drop' (k - wcwidth' c) t'
- [] -> mempty
-
-take' :: Int -> String -> String
-take' k0 =
- rec k0
- where
- rec k t =
- if | (c : t') <- t, nc <- wcwidth' c, nc <= k ->
- c : rec (k - nc) t'
-
- | otherwise ->
- []
-
-splitAt' :: Int -> String -> (String, String)
-splitAt' k0 =
- rec k0 []
- where
- rec k a t =
- if | (c : t') <- t, nc <- wcwidth' c, nc <= k ->
- rec (k - nc) (c : a) t'
-
- | otherwise ->
- (reverse a, t)
-
--- TODO this breaks when WCWidth.wcwidth returns -1, which happens for
--- non-printable characters like '\n'.
--- Following wcwidth' isn't entirely correct because WCWidth.wcwidth '\0' == 0
-wcwidth' :: Char -> Int
-wcwidth' = max 1 . WCWidth.wcwidth
diff --git a/src/Blessings/Text.hs b/src/Blessings/Text.hs
deleted file mode 100644
index 04572dd..0000000
--- a/src/Blessings/Text.hs
+++ /dev/null
@@ -1,21 +0,0 @@
-{-# OPTIONS_GHC -fno-warn-orphans #-}
-
-module Blessings.Text
- ( module Blessings
- ) where
-
-import Blessings
-import Blessings.Internal
-import Data.Text (Text)
-import qualified Data.Text as T
-
-
-instance Blessable Text where
- length = T.length
- drop = T.drop
- take = T.take
- splitAt = T.splitAt
- break = T.break
- intercalate = T.intercalate
- fromWord8 = T.pack . Prelude.show
- show = T.pack . Prelude.show
diff --git a/src/Blessings/Text/WCWidth.hs b/src/Blessings/Text/WCWidth.hs
deleted file mode 100644
index 84e7cfa..0000000
--- a/src/Blessings/Text/WCWidth.hs
+++ /dev/null
@@ -1,66 +0,0 @@
-{-# LANGUAGE ImportQualifiedPost #-}
-{-# LANGUAGE MultiWayIf #-}
-{-# LANGUAGE PatternGuards #-}
-{-# OPTIONS_GHC -fno-warn-orphans #-}
-module Blessings.Text.WCWidth
- ( module Blessings
- ) where
-
-import Blessings
-import Blessings.Internal
-import Data.Char.WCWidth qualified as WCWidth
-import Data.Text (Text)
-import Data.Text qualified as Text
-
-
-instance Blessable Text where
- length = length'
- drop = drop'
- take = take'
- splitAt = splitAt'
- break = Text.break
- intercalate = Text.intercalate
- fromWord8 = Text.pack . Prelude.show
- show = Text.pack . Prelude.show
-
-
-length' :: Text -> Int
-length' = Text.foldr ((+) . wcwidth') 0
-
-drop' :: Int -> Text -> Text
-drop' k t =
- if k <= 0
- then t
- else
- case Text.uncons t of
- Just (c, t') ->
- drop' (k - wcwidth' c) t'
- Nothing -> mempty
-
-take' :: Int -> Text -> Text
-take' k0 =
- Text.pack . rec k0
- where
- rec k t =
- if | Just (c, t') <- Text.uncons t, nc <- wcwidth' c, nc <= k ->
- c : rec (k - nc) t'
-
- | otherwise ->
- []
-
-splitAt' :: Int -> Text -> (Text, Text)
-splitAt' k0 =
- rec k0 mempty
- where
- rec k a t =
- if | Just (c, t') <- Text.uncons t, nc <- wcwidth' c, nc <= k ->
- rec (k - nc) (c : a) t'
-
- | otherwise ->
- (Text.pack $ reverse a, t)
-
--- TODO this breaks when WCWidth.wcwidth returns -1, which happens for
--- non-printable characters like '\n'.
--- Following wcwidth' isn't entirely correct because WCWidth.wcwidth '\0' == 0
-wcwidth' :: Char -> Int
-wcwidth' = max 1 . WCWidth.wcwidth