string-variants 0.2.0.0 → 0.2.1.0
raw patch · 4 files changed
+17/−6 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.StringVariants: chunksOfNonEmptyText :: forall chunkSize totalSize. (KnownNat chunkSize, KnownNat totalSize, chunkSize <= totalSize, 1 <= chunkSize) => NonEmptyText totalSize -> [NonEmptyText chunkSize]
+ Data.StringVariants: chunksOfNonEmptyText :: forall chunkSize totalSize. (KnownNat chunkSize, KnownNat totalSize, chunkSize <= totalSize, 1 <= chunkSize) => NonEmptyText totalSize -> NonEmpty (NonEmptyText chunkSize)
- Data.StringVariants.NonEmptyText: chunksOfNonEmptyText :: forall chunkSize totalSize. (KnownNat chunkSize, KnownNat totalSize, chunkSize <= totalSize, 1 <= chunkSize) => NonEmptyText totalSize -> [NonEmptyText chunkSize]
+ Data.StringVariants.NonEmptyText: chunksOfNonEmptyText :: forall chunkSize totalSize. (KnownNat chunkSize, KnownNat totalSize, chunkSize <= totalSize, 1 <= chunkSize) => NonEmptyText totalSize -> NonEmpty (NonEmptyText chunkSize)
Files
- CHANGELOG.md +4/−0
- src/Data/StringVariants/NonEmptyText.hs +8/−2
- string-variants.cabal +2/−2
- test/Specs/TextManipulationSpec.hs +3/−2
CHANGELOG.md view
@@ -1,5 +1,9 @@ # Changelog +## [0.2.1.0] - 2023-01-23++- Use `NonEmptyList` for `chunksOfNonEmptyText`+ ## [0.2.0.0] - 2022-12-05 - Add `literalNonEmptyText`, `literalProse`, `literalNullableNonEmptyText` for creation of string variants from the type-level literals.
src/Data/StringVariants/NonEmptyText.hs view
@@ -41,6 +41,7 @@ import Control.Monad import Data.Data (Proxy (..), typeRep)+import Data.List.NonEmpty qualified as NE import Data.Maybe (mapMaybe) import Data.StringVariants.NonEmptyText.Internal import Data.StringVariants.Util@@ -120,10 +121,15 @@ forall chunkSize totalSize. (KnownNat chunkSize, KnownNat totalSize, chunkSize <= totalSize, 1 <= chunkSize) => NonEmptyText totalSize ->- [NonEmptyText chunkSize]+ NE.NonEmpty (NonEmptyText chunkSize) chunksOfNonEmptyText (NonEmptyText t) =- mapMaybe mkNonEmptyText (T.chunksOf chunkSize t)+ case mNonEmptyChunks of+ Nothing -> error $ "chunksOfNonEmptyText: invalid input: " <> show t+ Just chunks -> chunks where+ -- The function NE.nonEmpty is safer than partial NE.fromList.+ -- If the input NonEmptyText is invalid, we want to return a detailed error message.+ mNonEmptyChunks = NE.nonEmpty $ mapMaybe mkNonEmptyText (T.chunksOf chunkSize t) chunkSize = fromIntegral $ natVal (Proxy @chunkSize) -- | Concat two NonEmptyText values, with the new maximum length being the sum of the two
string-variants.cabal view
@@ -5,13 +5,13 @@ -- see: https://github.com/sol/hpack name: string-variants-version: 0.2.0.0+version: 0.2.1.0 synopsis: Constrained text newtypes description: See README at <https://github.com/MercuryTechnologies/string-variants#readme>. category: Data homepage: https://github.com/MercuryTechnologies/string-variants#readme bug-reports: https://github.com/MercuryTechnologies/string-variants/issues-maintainer: Jade Lovelace <jadel@mercury.com>, Borys Lykakh <borys@fastmail.com>+maintainer: Jade Lovelace <jadel@mercury.com>, Borys Lykakh <lykahb@fastmail.com> license: MIT license-file: LICENSE build-type: Simple
test/Specs/TextManipulationSpec.hs view
@@ -3,6 +3,7 @@ module Specs.TextManipulationSpec (spec) where import Data.Char+import Data.List.NonEmpty (NonEmpty (..)) import Data.StringVariants.NonEmptyText import Test.Hspec import Prelude@@ -32,7 +33,7 @@ describe "chunksOfNonEmptyText" $ do it "chunksOfNonEmptyText drops empty chunks" $ do chunksOfNonEmptyText [compileNonEmptyTextKnownLength|a b|]- `shouldBe` ([[compileNonEmptyTextKnownLength|a|], [compileNonEmptyTextKnownLength|b|]] :: [NonEmptyText 1])+ `shouldBe` ([compileNonEmptyTextKnownLength|a|] :| [[compileNonEmptyTextKnownLength|b|]] :: NonEmpty (NonEmptyText 1)) it "chunksOfNonEmptyText strips chunks" $ do chunksOfNonEmptyText [compileNonEmptyTextKnownLength|a b|]- `shouldBe` ([widen [compileNonEmptyTextKnownLength|a|], widen [compileNonEmptyTextKnownLength|b|]] :: [NonEmptyText 2])+ `shouldBe` (widen [compileNonEmptyTextKnownLength|a|] :| [widen [compileNonEmptyTextKnownLength|b|]] :: NonEmpty (NonEmptyText 2))