module HBS2.Prelude ( module Data.String , module Safe , module X , MonadIO(..) , void, guard, when, unless , maybe1 , eitherToMaybe , Hashable , lift , AsFileName(..) -- , Pretty , FromStringMaybe(..) , none , module Prettyprinter , ToByteString(..) , FromByteString(..) , Text.Text ) where import Data.Typeable as X import GHC.Generics as X (Generic) import Data.ByteString (ByteString) import Data.String (IsString(..)) import Safe import Control.Concurrent.Async as X (ExceptionInLinkedThread) import Control.Monad.IO.Class (MonadIO(..)) import Control.Monad (void,guard,when,unless) import Control.Monad.Trans.Class (lift) import Control.Monad.IO.Unlift as X import Data.Char qualified as Char import Data.Function import Data.Hashable import Data.Text qualified as Text import Data.Word import Prettyprinter import UnliftIO as X (MonadUnliftIO(..)) import UnliftIO.Async as X none :: forall m . Monad m => m () none = pure () maybe1 :: Maybe a -> b -> (a -> b) -> b maybe1 mb n j = maybe n j mb eitherToMaybe :: Either a b -> Maybe b eitherToMaybe = either (const Nothing) Just newtype AsFileName a = AsFileName a instance Pretty a => Pretty (AsFileName a) where pretty (AsFileName f) = pretty x <> "@" <> uniq where uniq = pretty (fromIntegral $ hash (show (pretty f)) :: Word16) x = show (pretty f) & Text.pack & Text.filter (not . Char.isPunctuation) class FromStringMaybe a where fromStringMay :: String -> Maybe a class ToByteString a where toByteString :: a -> ByteString class FromByteString a where fromByteString :: ByteString -> Maybe a