Skip to content

Commit 5e03c27

Browse files
committed
Make RegexFlags a newtype
1 parent d9ba5d0 commit 5e03c27

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Bugfixes:
1515

1616
Other improvements:
1717
- Surround code with backticks in documentation (#148)
18+
- Make `RegexFlags` a `newtype` and a `Newtype` instance for it(#159 by @mhmdanas)
1819

1920
## [v5.0.0](https://github.com/purescript/purescript-strings/releases/tag/v5.0.0) - 2021-02-26
2021

src/Data/String/Regex/Flags.purs

+5-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Data.String.Regex.Flags where
33
import Prelude
44

55
import Control.MonadPlus (guard)
6+
import Data.Newtype (class Newtype)
67
import Data.String (joinWith)
78

89
type RegexFlagsRec =
@@ -15,7 +16,9 @@ type RegexFlagsRec =
1516
}
1617

1718
-- | Flags that control matching.
18-
data RegexFlags = RegexFlags RegexFlagsRec
19+
newtype RegexFlags = RegexFlags RegexFlagsRec
20+
21+
derive instance newtypeRegexFlags :: Newtype RegexFlags _
1922

2023
-- | All flags set to false.
2124
noFlags :: RegexFlags
@@ -107,14 +110,7 @@ instance semigroupRegexFlags :: Semigroup RegexFlags where
107110
instance monoidRegexFlags :: Monoid RegexFlags where
108111
mempty = noFlags
109112

110-
instance eqRegexFlags :: Eq RegexFlags where
111-
eq (RegexFlags x) (RegexFlags y)
112-
= x.global == y.global
113-
&& x.ignoreCase == y.ignoreCase
114-
&& x.multiline == y.multiline
115-
&& x.dotAll == y.dotAll
116-
&& x.sticky == y.sticky
117-
&& x.unicode == y.unicode
113+
derive newtype instance eqRegexFlags :: Eq RegexFlags
118114

119115
instance showRegexFlags :: Show RegexFlags where
120116
show (RegexFlags flags) =

0 commit comments

Comments
 (0)