Skip to content

Commit

Permalink
Add more typeclass instances for NonEmptyText and NullableNonEmptyText (
Browse files Browse the repository at this point in the history
#21)

* add some more instances

* update package list and add typeclass derivations

* fix version number

* update changelog

* fix typo in changelog

* Delete result file--accidentally committed this build artefact
  • Loading branch information
curranosaurus authored Oct 31, 2024
1 parent 8d11985 commit dc33925
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [0.3.1.1] - 2024-10-31

- Add `Hashable` and `NFData` instances to `NonEmptyText`.
- Add `Data`, `Ord`, `Hashable` and `NFData` instances to `NullableNonEmptyText`.
- Add dependencies on `deepseq` and `hashable`.

## [0.3.1.0] - 2024-02-29

- Add `Data` instance to `NonEmptyText`.
Expand Down
4 changes: 3 additions & 1 deletion package.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: string-variants
version: 0.3.0.1
version: 0.3.1.1
synopsis: Constrained text newtypes
description: See README at <https://github.com/MercuryTechnologies/string-variants#readme>.
category: Data
Expand All @@ -24,6 +24,8 @@ library:
dependencies:
- QuickCheck
- bytestring
- deepseq
- hashable
- mono-traversable
- refined
- string-conversions
Expand Down
4 changes: 3 additions & 1 deletion src/Data/StringVariants/NonEmptyText/Internal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

module Data.StringVariants.NonEmptyText.Internal where

import Control.DeepSeq (NFData)
import Control.Monad (when)
import Data.Aeson (FromJSON (..), ToJSON, withText)
import Data.ByteString
import Data.Coerce
import Data.Data (Data)
import Data.Hashable (Hashable)
import Data.MonoTraversable
import Data.Proxy
import Data.Sequences
Expand All @@ -33,7 +35,7 @@ import Prelude
-- | Non Empty Text, requires the input is between 1 and @n@ chars and not just whitespace.
newtype NonEmptyText (n :: Nat) = NonEmptyText Text
deriving stock (Data, Generic, Show, Read, Lift)
deriving newtype (Eq, Ord, ToJSON, MonoFoldable)
deriving newtype (Eq, Ord, ToJSON, MonoFoldable, Hashable, NFData)

type instance Element (NonEmptyText _n) = Char

Expand Down
11 changes: 8 additions & 3 deletions src/Data/StringVariants/NullableNonEmptyText.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
Expand Down Expand Up @@ -30,14 +31,18 @@ module Data.StringVariants.NullableNonEmptyText
)
where

import Control.DeepSeq (NFData)
import Control.Monad
import Data.Aeson
import Data.Aeson qualified as J
import Data.Aeson.Key qualified as J
import Data.Aeson.Types qualified as J
import Data.Data (Proxy (..))
import Data.Data (Data, Proxy (..))
import Data.Hashable (Hashable)
import Data.Maybe (fromMaybe)
import Data.MonoTraversable (MonoFoldable)
import Data.StringVariants.NonEmptyText
import Data.StringVariants.NonEmptyText.Internal (NonEmptyText (..))
import Data.StringVariants.Util
import Data.Text (Text)
import Data.Text qualified as T
Expand Down Expand Up @@ -80,8 +85,8 @@ import Prelude
--
-- Use 'nullableNonEmptyTextToMaybeNonEmptyText' to extract @Maybe (NonEmptyText n)@ from @NullableNonEmptyText n@.
newtype NullableNonEmptyText n = NullableNonEmptyText (Maybe (NonEmptyText n))
deriving stock (Generic, Show, Read, Lift)
deriving newtype (Eq)
deriving stock (Data, Generic, Show, Read, Lift)
deriving newtype (Eq, Ord, Hashable, NFData)

mkNullableNonEmptyText :: forall n. (KnownNat n, 1 <= n) => Text -> Maybe (NullableNonEmptyText n)
mkNullableNonEmptyText t
Expand Down
4 changes: 3 additions & 1 deletion string-variants.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ cabal-version: 1.12
-- see: https://github.com/sol/hpack

name: string-variants
version: 0.3.1.0
version: 0.3.1.1
synopsis: Constrained text newtypes
description: See README at <https://github.com/MercuryTechnologies/string-variants#readme>.
category: Data
Expand Down Expand Up @@ -79,6 +79,8 @@ library
, aeson >=2.0.0.0
, base >=4.16 && <5
, bytestring
, deepseq
, hashable
, mono-traversable
, refined
, string-conversions
Expand Down

0 comments on commit dc33925

Please sign in to comment.