string-like-0.1.0.1: A package that aims to provide a uniform interface to string-like types.
Maintainerhapytexeu+gh@gmail.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe
LanguageHaskell2010

Data.String.Like

Description

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

Documentation

class IsString a => StringLike a where Source #

A typeclass that provides a uniform interface for string-like objects.

Minimal complete definition

fromText, toText | toString

Methods

empty :: a Source #

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.

length :: a -> Int Source #

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 Chars in the string-like object satisfy a given condition.

strAll :: (Char -> Bool) -> a -> Bool Source #

Check if all of the Chars of the string-like object satisfy a given condition.

strNull :: a -> Bool Source #

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.

reverse :: a -> a Source #

Calculate the reverse string of the given string.

toLower :: a -> a Source #

Convert the given string-like object to its lowercase equivalent.

toUpper :: a -> a Source #

Convert the given string-like object to its uppercase equivalent.

toTitle :: a -> a Source #

Convert the given string-like object to its title-case equivalent.

fromText :: Text -> a Source #

Convert a Text object to the string-like object.

toText :: a -> Text Source #

Convert the string-like object to an Text object.

Instances

Instances details
StringLike ByteString Source # 
Instance details

Defined in Data.String.Like

StringLike ByteString Source # 
Instance details

Defined in Data.String.Like

StringLike Text Source # 
Instance details

Defined in Data.String.Like

StringLike Text Source # 
Instance details

Defined in Data.String.Like

StringLike [Char] Source # 
Instance details

Defined in Data.String.Like

class IsString a where #

Class for string-like datastructures; used by the overloaded string extension (-XOverloadedStrings in GHC).

Methods

fromString :: String -> a #

Instances

Instances details
IsString ByteString 
Instance details

Defined in Data.ByteString.Lazy.Internal

IsString ByteString 
Instance details

Defined in Data.ByteString.Internal

a ~ Char => IsString [a]

(a ~ Char) context was introduced in 4.9.0.0

Since: base-2.1

Instance details

Defined in Data.String

Methods

fromString :: String -> [a] #

IsString a => IsString (Identity a)

Since: base-4.9.0.0

Instance details

Defined in Data.String

Methods

fromString :: String -> Identity a #

IsString a => IsString (Const a b)

Since: base-4.9.0.0

Instance details

Defined in Data.String

Methods

fromString :: String -> Const a b #

convertStringLike Source #

Arguments

:: (StringLike a, StringLike b) 
=> a

The StringLike object to convert.

-> b

The StringLike object that is the equivalent of the given StringLike object.

Convert from one StringLike type to another StringLike type. This is done through a lazy Text.