Data.String.NonEmpty.CodeUnits
#fromCharArray
fromCharArray :: Array Char -> Maybe NonEmptyString
Creates a NonEmptyString
from a character array String
, returning
Nothing
if the input is empty.
fromCharArray [] = Nothing
fromCharArray ['a', 'b', 'c'] = Just (NonEmptyString "abc")
#fromNonEmptyCharArray
#singleton
singleton :: Char -> NonEmptyString
Creates a NonEmptyString
from a character.
#cons
cons :: Char -> String -> NonEmptyString
Creates a NonEmptyString
from a string by prepending a character.
cons 'a' "bc" = NonEmptyString "abc"
cons 'a' "" = NonEmptyString "a"
#snoc
snoc :: Char -> String -> NonEmptyString
Creates a NonEmptyString
from a string by appending a character.
snoc 'c' "ab" = NonEmptyString "abc"
snoc 'a' "" = NonEmptyString "a"
#fromFoldable1
fromFoldable1 :: forall f. Foldable1 f => f Char -> NonEmptyString
Creates a NonEmptyString
from a Foldable1
container carrying
characters.
#toCharArray
toCharArray :: NonEmptyString -> Array Char
Converts the NonEmptyString
into an array of characters.
toCharArray (NonEmptyString "Hello☺\n") == ['H','e','l','l','o','☺','\n']
#toNonEmptyCharArray
toNonEmptyCharArray :: NonEmptyString -> NonEmptyArray Char
Converts the NonEmptyString
into a non-empty array of characters.
#charAt
charAt :: Int -> NonEmptyString -> Maybe Char
Returns the character at the given index, if the index is within bounds.
charAt 2 (NonEmptyString "Hello") == Just 'l'
charAt 10 (NonEmptyString "Hello") == Nothing
#toChar
toChar :: NonEmptyString -> Maybe Char
Converts the NonEmptyString
to a character, if the length of the string
is exactly 1
.
toChar "H" == Just 'H'
toChar "Hi" == Nothing
#indexOf
indexOf :: Pattern -> NonEmptyString -> Maybe Int
Returns 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'
indexOf' :: Pattern -> Int -> NonEmptyString -> Maybe Int
Returns 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
lastIndexOf :: Pattern -> NonEmptyString -> Maybe Int
Returns 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'
lastIndexOf' :: Pattern -> Int -> NonEmptyString -> Maybe Int
Returns 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.
Returns Nothing
if there is no match.
lastIndexOf' (Pattern "a") 1 (NonEmptyString "ababa") == Just 0
lastIndexOf' (Pattern "a") 3 (NonEmptyString "ababa") == Just 2
lastIndexOf' (Pattern "a") 4 (NonEmptyString "ababa") == Just 4
#uncons
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
length :: NonEmptyString -> Int
Returns the number of characters the string is composed of.
length (NonEmptyString "Hello World") == 11
#take
take :: Int -> NonEmptyString -> Maybe NonEmptyString
Returns 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
takeRight :: Int -> NonEmptyString -> Maybe NonEmptyString
Returns 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
takeWhile :: (Char -> Boolean) -> NonEmptyString -> Maybe NonEmptyString
Returns 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
drop :: Int -> NonEmptyString -> Maybe NonEmptyString
Returns 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
dropRight :: Int -> NonEmptyString -> Maybe NonEmptyString
Returns 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
dropWhile :: (Char -> Boolean) -> NonEmptyString -> Maybe NonEmptyString
Returns the suffix remaining after takeWhile
.
dropWhile (_ /= '.') (NonEmptyString "Test.purs") == Just (NonEmptyString ".purs")
#countPrefix
countPrefix :: (Char -> Boolean) -> NonEmptyString -> Int
Returns the number of contiguous characters at the beginning of the string for which the predicate holds.
countPrefix (_ /= 'o') (NonEmptyString "Hello World") == 4
#splitAt
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
- Control.Alt
- Control.Alternative
- Control.Applicative
- Control.Apply
- Control.Biapplicative
- Control.Biapply
- Control.Bind
- Control.Category
- Control.Comonad
- Control.Extend
- Control.Lazy
- Control.Monad
- Control.Monad.Gen
- Control.Monad.Gen.Class
- Control.Monad.Gen.Common
- Control.Monad.Rec.Class
- Control.Monad.ST
- Control.Monad.ST.Class
- Control.Monad.ST.Global
- Control.Monad.ST.Internal
- Control.Monad.ST.Ref
- Control.MonadPlus
- Control.MonadZero
- Control.Plus
- Control.Semigroupoid
- Data.Array
- Data.Array.NonEmpty
- Data.Array.NonEmpty.Internal
- Data.Array.Partial
- Data.Array.ST
- Data.Array.ST.Iterator
- Data.Array.ST.Partial
- Data.Bifoldable
- Data.Bifunctor
- Data.Bifunctor.Clown
- Data.Bifunctor.Flip
- Data.Bifunctor.Join
- Data.Bifunctor.Joker
- Data.Bifunctor.Product
- Data.Bifunctor.Wrap
- Data.Bitraversable
- Data.Boolean
- Data.BooleanAlgebra
- Data.Bounded
- Data.Char
- Data.Char.Gen
- Data.Char.Utils
- Data.CommutativeRing
- Data.Distributive
- Data.DivisionRing
- Data.Either
- Data.Either.Inject
- Data.Either.Nested
- Data.Enum
- Data.Enum.Gen
- Data.Eq
- Data.EuclideanRing
- Data.Field
- Data.Foldable
- Data.FoldableWithIndex
- Data.Function
- Data.Function.Uncurried
- Data.Functor
- Data.Functor.Invariant
- Data.FunctorWithIndex
- Data.HeytingAlgebra
- Data.Identity
- Data.Int
- Data.Int.Bits
- Data.Maybe
- Data.Maybe.First
- Data.Maybe.Last
- Data.Monoid
- Data.Monoid.Additive
- Data.Monoid.Alternate
- Data.Monoid.Conj
- Data.Monoid.Disj
- Data.Monoid.Dual
- Data.Monoid.Endo
- Data.Monoid.Multiplicative
- Data.NaturalTransformation
- Data.Newtype
- Data.NonEmpty
- Data.Ord
- Data.Ord.Down
- Data.Ord.Max
- Data.Ord.Min
- Data.Ord.Unsafe
- Data.Ordering
- Data.Ring
- Data.Semigroup
- Data.Semigroup.First
- Data.Semigroup.Foldable
- Data.Semigroup.Last
- Data.Semigroup.Traversable
- Data.Semiring
- Data.Show
- 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
- Data.String.Utils
- Data.Symbol
- Data.Traversable
- Data.Traversable.Accum
- Data.Traversable.Accum.Internal
- Data.TraversableWithIndex
- Data.Tuple
- Data.Tuple.Nested
- Data.Unfoldable
- Data.Unfoldable1
- Data.Unit
- Data.Void
- Effect
- Effect.Class
- Effect.Class.Console
- Effect.Console
- Effect.Ref
- Effect.Uncurried
- Effect.Unsafe
- Global
- Global.Unsafe
- MCPrelude
- Main
- Math
- PSCI.Support
- Partial
- Partial.Unsafe
- Prelude
- Prim
- Prim.Boolean
- Prim.Ordering
- Prim.Row
- Prim.RowList
- Prim.Symbol
- Prim.TypeError
- Record.Unsafe
- Type.Data.Row
- Type.Data.RowList
- Type.Equality
- Unsafe.Coerce