-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A type class to abstract between many different string types. -- @package str @version 0.1.0.0 module Text.Str -- | Str types are any type which can be thought as abstract -- strings; that is, ordered lists of Char. There are at least 3 -- commonly-used string types in Haskell (String, ByteString and Text), -- as well as newtyped strings. The interop with these types can -- be tedious or even bug-prone. Using Str allows functions to -- be written agnostically towards any particular type. It provides a set -- of commonly-needed string manipulation functions, and the ability to -- convert to and from a variety of string types, which lets us "borrow" -- existing functions which only operate on one of the types (see the -- various as- functions). Str extends several useful -- classes, perhaps most importantly IsString, which lets us use -- string literals to represent Strs. class (IsString s, Show s, Ord s, Hashable s, Monoid s) => Str s where toHex = asByteString encode lower = smap toLower upper = smap toUpper capitalize = asString $ \case { "" -> "" (c : cs) -> toUpper c : cs } trim = let f = reverse . dropWhile isSpace in f . f toString :: Str s => s -> String toByteString :: Str s => s -> ByteString toText :: Str s => s -> Text toOctets :: Str s => s -> [Octet] toHex :: Str s => s -> s fromText :: Str s => Text -> s fromByteString :: Str s => ByteString -> s fromOctets :: Str s => [Octet] -> s joinBy :: Str s => s -> [s] -> s splitOn :: Str s => s -> s -> [s] smap :: Str s => (Char -> Char) -> s -> s singleton :: Str s => Char -> s cons :: Str s => Char -> s -> s snoc :: Str s => s -> Char -> s lower :: Str s => s -> s upper :: Str s => s -> s capitalize :: Str s => s -> s reverse :: Str s => s -> s length :: Str s => s -> Int dropWhile :: Str s => (Char -> Bool) -> s -> s isPrefixOf :: Str s => s -> s -> Bool isSuffixOf :: Str s => s -> s -> Bool trim :: Str s => s -> s -- | Class for string-like datastructures; used by the overloaded string -- extension (-XOverloadedStrings in GHC). class IsString a fromString :: IsString a => String -> a -- | Generalizes show to return any string type. show :: (Show a, Str s) => a -> s -- | Generalizes error to accept any string type. error :: Str s => s -> a -- | Joins strings with newlines. joinLines :: Str s => [s] -> s -- | Joins strings with commas. joinCommas :: Str s => [s] -> s -- | Joins strings with semicolons. joinSemis :: Str s => [s] -> s -- | Joins strings with forward slashes. joinSlashes :: Str s => [s] -> s -- | Converts a function that operates on Strings to one that -- operates on any Str. asString :: Str s => (String -> String) -> s -> s -- | Converts a function that operates on ByteStrings to one that -- operates on any Str. asByteString :: Str s => (ByteString -> ByteString) -> s -> s -- | Converts a function that operates on Text to one that -- operates on any Str. asText :: Str s => (Text -> Text) -> s -> s -- | Same as asString but for functions with arity 2. asString2 :: Str s => (String -> String -> String) -> s -> s -> s -- | Same as asByteString but for functions with arity 2. asByteString2 :: Str s => (ByteString -> ByteString -> ByteString) -> s -> s -> s -- | Converts a function that takes a Text into one that takes any -- Str. wrapText :: Str s => (Text -> a) -> s -> a -- | Generalizes functions that take a String. wrapString :: Str s => (String -> a) -> s -> a -- | Generalizes functions that take a ByteString. wrapByteString :: Str s => (ByteString -> a) -> s -> a -- | Generalizes functions that take two ByteStrings. wrapByteString2 :: Str s => (ByteString -> ByteString -> a) -> s -> s -> a -- | Joins strings with newline separation, and adds a trailing newline. unlines :: Str s => [s] -> s -- | Generalizes putStrLn. putStrLn :: Str s => s -> IO () instance Str Text instance Str ByteString instance Str String