Maintainer | hapytexeu+gh@gmail.com |
---|---|
Stability | experimental |
Portability | POSIX |
Safe Haskell | Safe |
Language | Haskell2010 |
The module defines a typeclass that can be implemented to provide a uniform interface for String
-like objects (like String
, Text
, etc.).
The typeclass itself has default implementations that convert the StringLike
item first to a lazy Text
, then performs the operation, and
converts results back to its StringLike
object. This is usually not as efficient as an operation for that specific type. Therefore it is advisable
to implement the other functions as well. One can however decide to only implement fromText
and toText
; or toString
.
The module contains instances for String
, Text
, Text
, ByteString
and ByteString
.
Synopsis
- class IsString a => StringLike a where
- empty :: a
- cons :: Char -> a -> a
- snoc :: a -> Char -> a
- uncons :: a -> Maybe (Char, a)
- unsnoc :: a -> Maybe (a, Char)
- length :: a -> Int
- compareLength :: a -> Int -> Ordering
- toString :: a -> String
- fromChar :: Char -> a
- strConcat :: [a] -> a
- strConcatMap :: (Char -> a) -> a -> a
- strAny :: (Char -> Bool) -> a -> Bool
- strAll :: (Char -> Bool) -> a -> Bool
- strNull :: a -> Bool
- append :: a -> a -> a
- strMap :: (Char -> Char) -> a -> a
- intercalate :: a -> [a] -> a
- intersperse :: Char -> a -> a
- transpose :: [a] -> [a]
- reverse :: a -> a
- toLower :: a -> a
- toUpper :: a -> a
- toTitle :: a -> a
- fromText :: Text -> a
- toText :: a -> Text
- class IsString a where
- fromString :: String -> a
- convertStringLike :: (StringLike a, StringLike b) => a -> b
Documentation
class IsString a => StringLike a where Source #
A typeclass that provides a uniform interface for string-like objects.
Return an empty string-like object.
cons :: Char -> a -> a Source #
Create a stringlike object by prepending a Char
to an already
existing string-like object.
snoc :: a -> Char -> a Source #
Create a stringlike object by appending a Char
at the end of an
already existing string-like object.
uncons :: a -> Maybe (Char, a) Source #
Unpack a stringlike object by obtaining the first character, and
the rest of the string, given the string is non-empty. Nothing
otherwise.
unsnoc :: a -> Maybe (a, Char) Source #
Unpack a string-like object by obtaining te last character, and the
string without the last character, given the string is non-empty.
Nothing
otherwise.
Obtain the length of the string-like object.
compareLength :: a -> Int -> Ordering Source #
Compare the length of the string with the given length. Returns EQ
if
the string has the same length, LT
if the string is shorter, and GT
if the string is longer. If the length is not explicitly stored, this
function can stop from the moment the string-like object is exhausted, or
the threshold has been reached.
toString :: a -> String Source #
Convert the given string-like object to a String
. If not specified,
it will use toText
, and then unpack the Text
object in a String
.
fromChar :: Char -> a Source #
Convert a given Char
to a string-like object containing the single
character.
strConcat :: [a] -> a Source #
Concatenate the list of string-like objects to a string-like object.
strConcatMap :: (Char -> a) -> a -> a Source #
Create a string-like object by mapping each character to another string-like object, and concatenate these.
strAny :: (Char -> Bool) -> a -> Bool Source #
Check if any of the Char
s in the string-like object satisfy a given
condition.
strAll :: (Char -> Bool) -> a -> Bool Source #
Check if all of the Char
s of the string-like object satisfy a given
condition.
Check if the given string is empty.
append :: a -> a -> a Source #
Append two string-like objects to a new string-like object.
strMap :: (Char -> Char) -> a -> a Source #
Map all the characters of a string-like object to a new string-like object.
intercalate :: a -> [a] -> a Source #
Inserts the given string-like object in between the string-like objects in the list. For example to make a comma-separated string.
intersperse :: Char -> a -> a Source #
Inserts the given character in between the string-like objects in the list. For example to make a string of words.
transpose :: [a] -> [a] Source #
Transposes the rows and columns of the list of string-like objects.
Calculate the reverse string of the given string.
Convert the given string-like object to its lowercase equivalent.
Convert the given string-like object to its uppercase equivalent.
Convert the given string-like object to its title-case equivalent.
fromText :: Text -> a Source #
Convert a Text
object to the string-like object.
Convert the string-like object to an Text
object.
Instances
Class for string-like datastructures; used by the overloaded string extension (-XOverloadedStrings in GHC).
fromString :: String -> a #
Instances
IsString ByteString | |
Defined in Data.ByteString.Lazy.Internal fromString :: String -> ByteString # | |
IsString ByteString | |
Defined in Data.ByteString.Internal fromString :: String -> ByteString # | |
a ~ Char => IsString [a] |
Since: base-2.1 |
Defined in Data.String fromString :: String -> [a] # | |
IsString a => IsString (Identity a) | Since: base-4.9.0.0 |
Defined in Data.String fromString :: String -> Identity a # | |
IsString a => IsString (Const a b) | Since: base-4.9.0.0 |
Defined in Data.String fromString :: String -> Const a b # |
:: (StringLike a, StringLike b) | |
=> a | The |
-> b | The |
Convert from one StringLike
type to another StringLike
type. This is
done through a lazy Text
.