From 5e03c2793606919d805995f8d93ac25da1763f54 Mon Sep 17 00:00:00 2001 From: mhmdanas <32234660+mhmdanas@users.noreply.github.com> Date: Fri, 15 Apr 2022 21:55:47 +0300 Subject: [PATCH] Make `RegexFlags` a `newtype` --- CHANGELOG.md | 1 + src/Data/String/Regex/Flags.purs | 14 +++++--------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02cb63e..28863e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Bugfixes: Other improvements: - Surround code with backticks in documentation (#148) +- Make `RegexFlags` a `newtype` and a `Newtype` instance for it(#159 by @mhmdanas) ## [v5.0.0](https://github.com/purescript/purescript-strings/releases/tag/v5.0.0) - 2021-02-26 diff --git a/src/Data/String/Regex/Flags.purs b/src/Data/String/Regex/Flags.purs index dc7a0c7..49228f3 100644 --- a/src/Data/String/Regex/Flags.purs +++ b/src/Data/String/Regex/Flags.purs @@ -3,6 +3,7 @@ module Data.String.Regex.Flags where import Prelude import Control.MonadPlus (guard) +import Data.Newtype (class Newtype) import Data.String (joinWith) type RegexFlagsRec = @@ -15,7 +16,9 @@ type RegexFlagsRec = } -- | Flags that control matching. -data RegexFlags = RegexFlags RegexFlagsRec +newtype RegexFlags = RegexFlags RegexFlagsRec + +derive instance newtypeRegexFlags :: Newtype RegexFlags _ -- | All flags set to false. noFlags :: RegexFlags @@ -107,14 +110,7 @@ instance semigroupRegexFlags :: Semigroup RegexFlags where instance monoidRegexFlags :: Monoid RegexFlags where mempty = noFlags -instance eqRegexFlags :: Eq RegexFlags where - eq (RegexFlags x) (RegexFlags y) - = x.global == y.global - && x.ignoreCase == y.ignoreCase - && x.multiline == y.multiline - && x.dotAll == y.dotAll - && x.sticky == y.sticky - && x.unicode == y.unicode +derive newtype instance eqRegexFlags :: Eq RegexFlags instance showRegexFlags :: Show RegexFlags where show (RegexFlags flags) =