@@ -10,12 +10,14 @@ module Data.String.NonEmpty
1010 , fromString
1111 , unsafeFromString
1212 , fromCharArray
13+ , fromNonEmptyCharArray
1314 , singleton
1415 , cons
1516 , snoc
1617 , fromFoldable1
1718 , toString
1819 , toCharArray
20+ , toNonEmptyCharArray
1921 , charAt
2022 , charCodeAt
2123 , toChar
@@ -52,6 +54,8 @@ module Data.String.NonEmpty
5254
5355import Prelude
5456
57+ import Data.Array.NonEmpty (NonEmptyArray )
58+ import Data.Array.NonEmpty as NEA
5559import Data.Foldable (class Foldable )
5660import Data.Foldable as F
5761import Data.Maybe (Maybe (..), fromJust )
@@ -60,6 +64,7 @@ import Data.Semigroup.Foldable as F1
6064import Data.String (Pattern (..))
6165import Data.String as String
6266import Data.String.Unsafe as U
67+ import Partial.Unsafe (unsafePartial )
6368import Unsafe.Coerce (unsafeCoerce )
6469
6570-- | A string that is known not to be empty.
@@ -110,6 +115,9 @@ fromCharArray = case _ of
110115 [] -> Nothing
111116 cs -> Just (NonEmptyString (String .fromCharArray cs))
112117
118+ fromNonEmptyCharArray :: NonEmptyArray Char -> NonEmptyString
119+ fromNonEmptyCharArray = unsafePartial fromJust <<< fromCharArray <<< NEA .toArray
120+
113121-- | Creates a `NonEmptyString` from a character.
114122singleton :: Char -> NonEmptyString
115123singleton = NonEmptyString <<< String .singleton
@@ -181,6 +189,10 @@ toChar (NonEmptyString s) = String.toChar s
181189toCharArray :: NonEmptyString -> Array Char
182190toCharArray (NonEmptyString s) = String .toCharArray s
183191
192+ -- | Converts the `NonEmptyString` into a non-empty array of characters.
193+ toNonEmptyCharArray :: NonEmptyString -> NonEmptyArray Char
194+ toNonEmptyCharArray = unsafePartial fromJust <<< NEA .fromArray <<< toCharArray
195+
184196-- | Appends a string to this non-empty string. Since one of the strings is
185197-- | non-empty we know the result will be too.
186198-- |
0 commit comments