Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data NonEmptyText
- new :: Char -> Text -> NonEmptyText
- singleton :: Char -> NonEmptyText
- toText :: NonEmptyText -> Text
- fromText :: Text -> Maybe NonEmptyText
- cons :: Char -> NonEmptyText -> NonEmptyText
- snoc :: NonEmptyText -> Char -> NonEmptyText
- uncons :: NonEmptyText -> (Char, Text)
- unsnoc :: NonEmptyText -> (Text, Char)
- append :: NonEmptyText -> NonEmptyText -> NonEmptyText
- head :: NonEmptyText -> Char
- last :: NonEmptyText -> Char
- tail :: NonEmptyText -> Text
- init :: NonEmptyText -> Text
- length :: NonEmptyText -> Int
- map :: (Char -> Char) -> NonEmptyText -> NonEmptyText
- isSingleton :: NonEmptyText -> Bool
- foldl1 :: (Char -> Char -> Char) -> NonEmptyText -> Char
- foldl1' :: (Char -> Char -> Char) -> NonEmptyText -> Char
Documentation
data NonEmptyText Source #
Instances
Creation
new :: Char -> Text -> NonEmptyText Source #
O(1) Create a new NonEmptyText
>>>
new 'h' "ello world"
"hello world"
singleton :: Char -> NonEmptyText Source #
O(1) Convert a character into a NonEmptyText
.
>>>
singleton 'a'
"a"
toText :: NonEmptyText -> Text Source #
O(n) Convert to NonEmptyText to Text.
The Text
result is guaranteed to be non-empty. However, this is
not reflected in the type.
fromText :: Text -> Maybe NonEmptyText Source #
O(n) Create a NonEmptyText
from Text
.
If the original text is empty, this will return Nothing
.
>>>
fromText "hello"
Just "hello">>>
fromText ""
Nothing
Basic interface
cons :: Char -> NonEmptyText -> NonEmptyText Source #
O(n) Prefixes the NonEmptyText
with one character
snoc :: NonEmptyText -> Char -> NonEmptyText Source #
O(n) Suffixes the NonEmptyText
with one character
uncons :: NonEmptyText -> (Char, Text) Source #
O(1) Return the first character and the rest of the NonEmptyText
unsnoc :: NonEmptyText -> (Text, Char) Source #
O(n) Return the beginning of the NonEmptyText
, and its last character
append :: NonEmptyText -> NonEmptyText -> NonEmptyText Source #
O(n) Appends one NonEmptyText
to another
>>>
append <$> fromText "hello," <*> fromText " world."
Just "hello, world."
head :: NonEmptyText -> Char Source #
O(1) Return the first of the NonEmptyText
As opposed to head
, this is guaranteed to succeed, as the
the text is never empty.
last :: NonEmptyText -> Char Source #
O(1) Return the last character of the NonEmptyText
This never fails.
tail :: NonEmptyText -> Text Source #
O(1) Return all characters of the NonEmptyText
but the first one
init :: NonEmptyText -> Text Source #
O(n) Return all character of the NonEmptyText
but the last one
length :: NonEmptyText -> Int Source #
O(n) Return the length of the total NonEmptyText
.
map :: (Char -> Char) -> NonEmptyText -> NonEmptyText Source #
O(n) map
f
t
is the NonEmptyText
obtained by applying f
to
each element of t
.
isSingleton :: NonEmptyText -> Bool Source #
O(1) Check if the string is composed of only one character