module Skulk.ToString where
import Data.Maybe(fromMaybe,maybe)
import Data.String(IsString,fromString)
class ToString w where
toString :: w -> String
instance (ToString a, ToString b) => ToString (Either a b) where
toString = either toString toString
instance ToString String where
toString = id
instance ToString a => ToString (Maybe a) where
toString = maybe "" toString
liftT :: (ToString a, IsString a) => (String -> String) -> a -> a
liftT f = fromString . f . toString
shapeshift :: (ToString a, IsString b) => a -> b
shapeshift = fromString . toString
emptyToNothing :: ToString a => a -> Maybe a
emptyToNothing x | null (toString x) = Nothing | otherwise = Just x
nothingToEmpty :: IsString a => Maybe a -> a
nothingToEmpty = fromMaybe (fromString "")