@@ -8,6 +8,7 @@ module Data.String.NonEmpty
8
8
( NonEmptyString
9
9
, NonEmptyReplacement (..)
10
10
, fromString
11
+ , unsafeFromString
11
12
, fromCharArray
12
13
, singleton
13
14
, cons
@@ -53,7 +54,7 @@ import Prelude
53
54
54
55
import Data.Foldable (class Foldable )
55
56
import Data.Foldable as F
56
- import Data.Maybe (Maybe (..))
57
+ import Data.Maybe (Maybe (..), fromJust )
57
58
import Data.Semigroup.Foldable (class Foldable1 )
58
59
import Data.Semigroup.Foldable as F1
59
60
import Data.String (Pattern (..))
@@ -69,7 +70,7 @@ derive newtype instance ordNonEmptyString ∷ Ord NonEmptyString
69
70
derive newtype instance semigroupNonEmptyString ∷ Semigroup NonEmptyString
70
71
71
72
instance showNonEmptyString :: Show NonEmptyString where
72
- show (NonEmptyString s) = " (NonEmptyString.fromString " <> show s <> " )"
73
+ show (NonEmptyString s) = " (NonEmptyString.unsafeFromString " <> show s <> " )"
73
74
74
75
-- | A newtype used in cases to specify a non-empty replacement for a pattern.
75
76
newtype NonEmptyReplacement = NonEmptyReplacement NonEmptyString
@@ -93,6 +94,10 @@ fromString = case _ of
93
94
" " -> Nothing
94
95
s -> Just (NonEmptyString s)
95
96
97
+ -- | A partial version of `fromString`.
98
+ unsafeFromString :: Partial => String -> NonEmptyString
99
+ unsafeFromString = fromJust <<< fromString
100
+
96
101
-- | Creates a `NonEmptyString` from a character array `String`, returning
97
102
-- | `Nothing` if the input is empty.
98
103
-- |
0 commit comments