Data.String.NonEmpty.CodeUnits
- Package
- purescript-strings
- Repository
- purescript/purescript-strings
#fromCharArray Source
fromCharArray :: Array Char -> Maybe NonEmptyStringCreates a NonEmptyString from a character array String, returning
Nothing if the input is empty.
fromCharArray [] = Nothing
fromCharArray ['a', 'b', 'c'] = Just (NonEmptyString "abc")
#singleton Source
singleton :: Char -> NonEmptyStringCreates a NonEmptyString from a character.
#cons Source
cons :: Char -> String -> NonEmptyStringCreates a NonEmptyString from a string by prepending a character.
cons 'a' "bc" = NonEmptyString "abc"
cons 'a' "" = NonEmptyString "a"
#snoc Source
snoc :: Char -> String -> NonEmptyStringCreates a NonEmptyString from a string by appending a character.
snoc 'c' "ab" = NonEmptyString "abc"
snoc 'a' "" = NonEmptyString "a"
#fromFoldable1 Source
fromFoldable1 :: forall f. Foldable1 f => f Char -> NonEmptyStringCreates a NonEmptyString from a Foldable1 container carrying
characters.
#toCharArray Source
toCharArray :: NonEmptyString -> Array CharConverts the NonEmptyString into an array of characters.
toCharArray (NonEmptyString "Hello☺\n") == ['H','e','l','l','o','☺','\n']
#toNonEmptyCharArray Source
toNonEmptyCharArray :: NonEmptyString -> NonEmptyArray CharConverts the NonEmptyString into a non-empty array of characters.
#charAt Source
charAt :: Int -> NonEmptyString -> Maybe CharReturns the character at the given index, if the index is within bounds.
charAt 2 (NonEmptyString "Hello") == Just 'l'
charAt 10 (NonEmptyString "Hello") == Nothing
#toChar Source
toChar :: NonEmptyString -> Maybe CharConverts the NonEmptyString to a character, if the length of the string
is exactly 1.
toChar "H" == Just 'H'
toChar "Hi" == Nothing
#indexOf Source
indexOf :: Pattern -> NonEmptyString -> Maybe IntReturns the index of the first occurrence of the pattern in the
given string. Returns Nothing if there is no match.
indexOf (Pattern "c") (NonEmptyString "abcdc") == Just 2
indexOf (Pattern "c") (NonEmptyString "aaa") == Nothing
#indexOf' Source
indexOf' :: Pattern -> Int -> NonEmptyString -> Maybe IntReturns the index of the first occurrence of the pattern in the
given string, starting at the specified index. Returns Nothing if there is
no match.
indexOf' (Pattern "a") 2 (NonEmptyString "ababa") == Just 2
indexOf' (Pattern "a") 3 (NonEmptyString "ababa") == Just 4
#lastIndexOf Source
lastIndexOf :: Pattern -> NonEmptyString -> Maybe IntReturns the index of the last occurrence of the pattern in the
given string. Returns Nothing if there is no match.
lastIndexOf (Pattern "c") (NonEmptyString "abcdc") == Just 4
lastIndexOf (Pattern "c") (NonEmptyString "aaa") == Nothing
#lastIndexOf' Source
lastIndexOf' :: Pattern -> Int -> NonEmptyString -> Maybe IntReturns the index of the last occurrence of the pattern in the given string, starting at the specified index and searching backwards towards the beginning of the string.
Starting at a negative index is equivalent to starting at 0 and starting at an index greater than the string length is equivalent to searching in the whole string.
Returns Nothing if there is no match.
lastIndexOf' (Pattern "a") (-1) (NonEmptyString "ababa") == Just 0
lastIndexOf' (Pattern "a") 1 (NonEmptyString "ababa") == Just 0
lastIndexOf' (Pattern "a") 3 (NonEmptyString "ababa") == Just 2
lastIndexOf' (Pattern "a") 4 (NonEmptyString "ababa") == Just 4
lastIndexOf' (Pattern "a") 5 (NonEmptyString "ababa") == Just 4
#uncons Source
uncons :: NonEmptyString -> { head :: Char, tail :: Maybe NonEmptyString }Returns the first character and the rest of the string.
uncons "a" == { head: 'a', tail: Nothing }
uncons "Hello World" == { head: 'H', tail: Just (NonEmptyString "ello World") }
#length Source
length :: NonEmptyString -> IntReturns the number of characters the string is composed of.
length (NonEmptyString "Hello World") == 11
#take Source
take :: Int -> NonEmptyString -> Maybe NonEmptyStringReturns the first n characters of the string. Returns Nothing if n is
less than 1.
take 5 (NonEmptyString "Hello World") == Just (NonEmptyString "Hello")
take 0 (NonEmptyString "Hello World") == Nothing
#takeRight Source
takeRight :: Int -> NonEmptyString -> Maybe NonEmptyStringReturns the last n characters of the string. Returns Nothing if n is
less than 1.
take 5 (NonEmptyString "Hello World") == Just (NonEmptyString "World")
take 0 (NonEmptyString "Hello World") == Nothing
#takeWhile Source
takeWhile :: (Char -> Boolean) -> NonEmptyString -> Maybe NonEmptyStringReturns the longest prefix of characters that satisfy the predicate.
Nothing is returned if there is no matching prefix.
takeWhile (_ /= ':') (NonEmptyString "http://purescript.org") == Just (NonEmptyString "http")
takeWhile (_ == 'a') (NonEmptyString "xyz") == Nothing
#drop Source
drop :: Int -> NonEmptyString -> Maybe NonEmptyStringReturns the string without the first n characters. Returns Nothing if
more characters are dropped than the string is long.
drop 6 (NonEmptyString "Hello World") == Just (NonEmptyString "World")
drop 20 (NonEmptyString "Hello World") == Nothing
#dropRight Source
dropRight :: Int -> NonEmptyString -> Maybe NonEmptyStringReturns the string without the last n characters. Returns Nothing if
more characters are dropped than the string is long.
dropRight 6 (NonEmptyString "Hello World") == Just (NonEmptyString "Hello")
dropRight 20 (NonEmptyString "Hello World") == Nothing
#dropWhile Source
dropWhile :: (Char -> Boolean) -> NonEmptyString -> Maybe NonEmptyStringReturns the suffix remaining after takeWhile.
dropWhile (_ /= '.') (NonEmptyString "Test.purs") == Just (NonEmptyString ".purs")
#countPrefix Source
countPrefix :: (Char -> Boolean) -> NonEmptyString -> IntReturns the number of contiguous characters at the beginning of the string for which the predicate holds.
countPrefix (_ /= 'o') (NonEmptyString "Hello World") == 4
#splitAt Source
splitAt :: Int -> NonEmptyString -> { after :: Maybe NonEmptyString, before :: Maybe NonEmptyString }Returns the substrings of a split at the given index, if the index is within bounds.
splitAt 2 (NonEmptyString "Hello World") == Just { before: Just (NonEmptyString "He"), after: Just (NonEmptyString "llo World") }
splitAt 10 (NonEmptyString "Hi") == Nothing
- Modules
- Data.
Char - Data.
Char. Gen - Data.
String - Data.
String. CaseInsensitive - Data.
String. CodePoints - Data.
String. CodeUnits - Data.
String. Common - Data.
String. Gen - Data.
String. NonEmpty - Data.
String. NonEmpty. CaseInsensitive - Data.
String. NonEmpty. CodePoints - Data.
String. NonEmpty. CodeUnits - Data.
String. NonEmpty. Internal - Data.
String. Pattern - Data.
String. Regex - Data.
String. Regex. Flags - Data.
String. Regex. Unsafe - Data.
String. Unsafe