@@ -8,6 +8,7 @@ module Data.String.NonEmpty
88 ( NonEmptyString
99 , NonEmptyReplacement (..)
1010 , fromString
11+ , unsafeFromString
1112 , fromCharArray
1213 , singleton
1314 , cons
@@ -53,7 +54,7 @@ import Prelude
5354
5455import Data.Foldable (class Foldable )
5556import Data.Foldable as F
56- import Data.Maybe (Maybe (..))
57+ import Data.Maybe (Maybe (..), fromJust )
5758import Data.Semigroup.Foldable (class Foldable1 )
5859import Data.Semigroup.Foldable as F1
5960import Data.String (Pattern (..))
@@ -69,7 +70,7 @@ derive newtype instance ordNonEmptyString ∷ Ord NonEmptyString
6970derive newtype instance semigroupNonEmptyString ∷ Semigroup NonEmptyString
7071
7172instance showNonEmptyString :: Show NonEmptyString where
72- show (NonEmptyString s) = " (NonEmptyString.fromString " <> show s <> " )"
73+ show (NonEmptyString s) = " (NonEmptyString.unsafeFromString " <> show s <> " )"
7374
7475-- | A newtype used in cases to specify a non-empty replacement for a pattern.
7576newtype NonEmptyReplacement = NonEmptyReplacement NonEmptyString
@@ -93,6 +94,10 @@ fromString = case _ of
9394 " " -> Nothing
9495 s -> Just (NonEmptyString s)
9596
97+ -- | A partial version of `fromString`.
98+ unsafeFromString :: Partial => String -> NonEmptyString
99+ unsafeFromString = fromJust <<< fromString
100+
96101-- | Creates a `NonEmptyString` from a character array `String`, returning
97102-- | `Nothing` if the input is empty.
98103-- |
0 commit comments