Skip to content

Commit b20217c

Browse files
committed
Merge branch 'develop' into use-commutative-semigroups
2 parents 33ac344 + b4f8f06 commit b20217c

File tree

12 files changed

+133
-37
lines changed

12 files changed

+133
-37
lines changed

ChangeLog.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Revision history for patch
22

3-
## Unreleased
3+
## 0.0.6.0 - 2022-06-10
4+
5+
* Add `PatchOrReplacement`, patch which either is some other patch type or a
6+
new replacement value.
47

58
* Use `commutative-semigroups` for `Commutative`, making `Additive` a
69
deprecated alias.

dep/reflex-platform/default.nix

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,2 @@
11
# DO NOT HAND-EDIT THIS FILE
2-
let fetch = { private ? false, fetchSubmodules ? false, owner, repo, rev, sha256, ... }:
3-
if !fetchSubmodules && !private then builtins.fetchTarball {
4-
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; inherit sha256;
5-
} else (import <nixpkgs> {}).fetchFromGitHub {
6-
inherit owner repo rev sha256 fetchSubmodules private;
7-
};
8-
in import (fetch (builtins.fromJSON (builtins.readFile ./github.json)))
2+
import (import ./thunk.nix)

dep/reflex-platform/github.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"owner": "reflex-frp",
33
"repo": "reflex-platform",
4-
"branch": "master",
4+
"branch": "develop",
55
"private": false,
6-
"rev": "c9d11db1b98855fe8ab24a3ff6a5dbe0ad902ad9",
7-
"sha256": "0sfzkqdvyah5mwvmli0wq1nl0b8cvk2cmfgfy4rz57wv42x3099y"
6+
"rev": "ac66356c8839d1dc16cc60887c2db5988a60e6c4",
7+
"sha256": "0zk8pf72lid6cqq4mlr1mcwh6zd5lz9i83kw519aci6mfba1afvq"
88
}

dep/reflex-platform/thunk.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# DO NOT HAND-EDIT THIS FILE
2+
let fetch = { private ? false, fetchSubmodules ? false, owner, repo, rev, sha256, ... }:
3+
if !fetchSubmodules && !private then builtins.fetchTarball {
4+
url = "https://github.com/${owner}/${repo}/archive/${rev}.tar.gz"; inherit sha256;
5+
} else (import <nixpkgs> {}).fetchFromGitHub {
6+
inherit owner repo rev sha256 fetchSubmodules private;
7+
};
8+
json = builtins.fromJSON (builtins.readFile ./github.json);
9+
in fetch json

patch.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Name: patch
2-
Version: 0.0.5.2
2+
Version: 0.0.6.0
33
Synopsis: Data structures for describing changes to other data structures.
44
Description:
55
Data structures for describing changes to other data structures.
@@ -58,6 +58,7 @@ library
5858
, Data.Patch.Map
5959
, Data.Patch.MapWithMove
6060
, Data.Patch.MapWithPatchingMove
61+
, Data.Patch.PatchOrReplacement
6162
, Data.Semigroup.Additive
6263

6364
ghc-options: -Wall -fwarn-redundant-constraints -fwarn-tabs

src/Data/Functor/Misc.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ module Data.Functor.Misc
4141
, ComposeMaybe (..)
4242
) where
4343

44-
import Control.Applicative ((<$>))
4544
import Data.Dependent.Map (DMap)
4645
import qualified Data.Dependent.Map as DMap
4746
import Data.Dependent.Sum
@@ -62,8 +61,9 @@ import Data.Typeable hiding (Refl)
6261
-- Const2
6362
--------------------------------------------------------------------------------
6463

65-
-- | 'Const2' stores a value of a given type 'k' and ensures that a particular
66-
-- type 'v' is always given for the last type parameter
64+
-- | @'Const2' k v v@ stores a value of a given type @k@ and ensures
65+
-- that a particular type @v@ is always given for the last type
66+
-- parameter
6767
data Const2 :: Type -> x -> x -> Type where
6868
Const2 :: k -> Const2 k v v
6969
deriving (Typeable)
@@ -228,9 +228,10 @@ dsumToEither = \case
228228
-- ComposeMaybe
229229
--------------------------------------------------------------------------------
230230

231-
-- | We can't use @Compose Maybe@ instead of 'ComposeMaybe', because that would
232-
-- make the 'f' parameter have a nominal type role. We need f to be
233-
-- representational so that we can use safe 'coerce'.
231+
-- | We can't use @'Data.Functor.Compose.Compose' 'Maybe'@ instead of @'ComposeMaybe'@,
232+
-- because that would make the @f@ parameter have a nominal type role.
233+
-- We need @f@ to be representational so that we can use safe
234+
-- @'Data.Coerce.coerce'@.
234235
newtype ComposeMaybe f a =
235236
ComposeMaybe { getComposeMaybe :: Maybe (f a) } deriving (Show, Eq, Ord)
236237

src/Data/Patch.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ module Data.Patch
1414
) where
1515

1616
import Data.Semigroup.Commutative
17-
import Control.Applicative
17+
import Control.Applicative (liftA2)
1818
import Data.Functor.Const (Const (..))
1919
import Data.Functor.Identity
2020
import Data.Map.Monoidal (MonoidalMap)

src/Data/Patch/IntMap.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ Patches of this sort allow for insert/update or delete of associations.
1515
module Data.Patch.IntMap where
1616

1717
import Control.Lens hiding (FunctorWithIndex, FoldableWithIndex, TraversableWithIndex)
18+
#if !MIN_VERSION_lens(5,0,0)
1819
import qualified Control.Lens as L
20+
#endif
1921
import Data.IntMap.Strict (IntMap)
2022
import qualified Data.IntMap.Strict as IntMap
2123
import Data.Maybe

src/Data/Patch/Map.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ module Data.Patch.Map where
1919
import Data.Patch.Class
2020

2121
import Control.Lens hiding (FunctorWithIndex, FoldableWithIndex, TraversableWithIndex)
22+
#if !MIN_VERSION_lens(5,0,0)
2223
import qualified Control.Lens as L
24+
#endif
2325
import Data.Map (Map)
2426
import qualified Data.Map as Map
2527
import Data.Maybe

src/Data/Patch/MapWithMove.hs

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ import Data.Patch.MapWithPatchingMove (PatchMapWithPatchingMove(..), To)
7171
import qualified Data.Patch.MapWithPatchingMove as PM -- already a transparent synonym
7272

7373
import Control.Lens hiding (FunctorWithIndex, FoldableWithIndex, TraversableWithIndex)
74+
#if !MIN_VERSION_lens(5,0,0)
7475
import qualified Control.Lens as L
76+
#endif
7577
import Data.List
7678
import Data.Map (Map)
7779
import qualified Data.Map as Map
@@ -109,8 +111,8 @@ pattern Coerce x <- (coerce -> x)
109111

110112
{-# COMPLETE PatchMapWithMove #-}
111113
pattern PatchMapWithMove :: Map k (NodeInfo k v) -> PatchMapWithMove k v
112-
-- | Extract the representation of the 'PatchMapWithMove' as a map of
113-
-- 'NodeInfo'.
114+
-- | Extract the representation of the t'PatchMapWithMove' as a map of
115+
-- t'NodeInfo'.
114116
unPatchMapWithMove :: PatchMapWithMove k v -> Map k (NodeInfo k v)
115117
pattern PatchMapWithMove { unPatchMapWithMove } = PatchMapWithMove' (PatchMapWithPatchingMove (Coerce unPatchMapWithMove))
116118

@@ -145,27 +147,27 @@ instance L.FoldableWithIndex k (PatchMapWithMove k) where ifoldMap = Data.Fold
145147
instance L.TraversableWithIndex k (PatchMapWithMove k) where itraverse = Data.Traversable.WithIndex.itraverse
146148
#endif
147149

148-
-- | Create a 'PatchMapWithMove', validating it
150+
-- | Create a t'PatchMapWithMove', validating it
149151
patchMapWithMove :: Ord k => Map k (NodeInfo k v) -> Maybe (PatchMapWithMove k v)
150152
patchMapWithMove = fmap PatchMapWithMove' . PM.patchMapWithPatchingMove . coerce
151153

152-
-- | Create a 'PatchMapWithMove' that inserts everything in the given 'Map'
154+
-- | Create a t'PatchMapWithMove' that inserts everything in the given 'Map'
153155
patchMapWithMoveInsertAll :: Map k v -> PatchMapWithMove k v
154156
patchMapWithMoveInsertAll = PatchMapWithMove' . PM.patchMapWithPatchingMoveInsertAll
155157

156-
-- | Make a @'PatchMapWithMove' k v@ which has the effect of inserting or updating a value @v@ to the given key @k@, like 'Map.insert'.
158+
-- | Make a @t'PatchMapWithMove' k v@ which has the effect of inserting or updating a value @v@ to the given key @k@, like 'Map.insert'.
157159
insertMapKey :: k -> v -> PatchMapWithMove k v
158160
insertMapKey k v = PatchMapWithMove' $ PM.insertMapKey k v
159161

160-
-- |Make a @'PatchMapWithMove' k v@ which has the effect of moving the value from the first key @k@ to the second key @k@, equivalent to:
162+
-- |Make a @t'PatchMapWithMove' k v@ which has the effect of moving the value from the first key @k@ to the second key @k@, equivalent to:
161163
--
162164
-- @
163165
-- 'Map.delete' src (maybe map ('Map.insert' dst) (Map.lookup src map))
164166
-- @
165167
moveMapKey :: Ord k => k -> k -> PatchMapWithMove k v
166168
moveMapKey src dst = PatchMapWithMove' $ PM.moveMapKey src dst
167169

168-
-- |Make a @'PatchMapWithMove' k v@ which has the effect of swapping two keys in the mapping, equivalent to:
170+
-- |Make a @t'PatchMapWithMove' k v@ which has the effect of swapping two keys in the mapping, equivalent to:
169171
--
170172
-- @
171173
-- let aMay = Map.lookup a map
@@ -177,13 +179,13 @@ moveMapKey src dst = PatchMapWithMove' $ PM.moveMapKey src dst
177179
swapMapKey :: Ord k => k -> k -> PatchMapWithMove k v
178180
swapMapKey src dst = PatchMapWithMove' $ PM.swapMapKey src dst
179181

180-
-- |Make a @'PatchMapWithMove' k v@ which has the effect of deleting a key in the mapping, equivalent to 'Map.delete'.
182+
-- |Make a @t'PatchMapWithMove' k v@ which has the effect of deleting a key in the mapping, equivalent to 'Map.delete'.
181183
deleteMapKey :: k -> PatchMapWithMove k v
182184
deleteMapKey = PatchMapWithMove' . PM.deleteMapKey
183185

184-
-- | Wrap a @'Map' k (NodeInfo k v)@ representing patch changes into a @'PatchMapWithMove' k v@, without checking any invariants.
186+
-- | Wrap a @'Map' k (NodeInfo k v)@ representing patch changes into a @t'PatchMapWithMove' k v@, without checking any invariants.
185187
--
186-
-- __Warning:__ when using this function, you must ensure that the invariants of 'PatchMapWithMove' are preserved; they will not be checked.
188+
-- __Warning:__ when using this function, you must ensure that the invariants of t'PatchMapWithMove' are preserved; they will not be checked.
187189
unsafePatchMapWithMove :: Map k (NodeInfo k v) -> PatchMapWithMove k v
188190
unsafePatchMapWithMove = coerce PM.unsafePatchMapWithPatchingMove
189191

@@ -196,25 +198,25 @@ instance Ord k => Patch (PatchMapWithMove k v) where
196198
patchMapWithMoveNewElements :: PatchMapWithMove k v -> [v]
197199
patchMapWithMoveNewElements = PM.patchMapWithPatchingMoveNewElements . unPatchMapWithMove'
198200

199-
-- | Return a @'Map' k v@ with all the inserts/updates from the given @'PatchMapWithMove' k v@.
201+
-- | Return a @'Map' k v@ with all the inserts/updates from the given @t'PatchMapWithMove' k v@.
200202
patchMapWithMoveNewElementsMap :: PatchMapWithMove k v -> Map k v
201203
patchMapWithMoveNewElementsMap = PM.patchMapWithPatchingMoveNewElementsMap . unPatchMapWithMove'
202204

203-
-- | Create a 'PatchMapWithMove' that, if applied to the given 'Map', will sort
205+
-- | Create a t'PatchMapWithMove' that, if applied to the given 'Map', will sort
204206
-- its values using the given ordering function. The set keys of the 'Map' is
205207
-- not changed.
206208
patchThatSortsMapWith :: Ord k => (v -> v -> Ordering) -> Map k v -> PatchMapWithMove k v
207209
patchThatSortsMapWith cmp = PatchMapWithMove' . PM.patchThatSortsMapWith cmp
208210

209-
-- | Create a 'PatchMapWithMove' that, if applied to the first 'Map' provided,
211+
-- | Create a t'PatchMapWithMove' that, if applied to the first 'Map' provided,
210212
-- will produce a 'Map' with the same values as the second 'Map' but with the
211213
-- values sorted with the given ordering function.
212214
patchThatChangesAndSortsMapWith :: (Ord k, Ord v) => (v -> v -> Ordering) -> Map k v -> Map k v -> PatchMapWithMove k v
213215
patchThatChangesAndSortsMapWith cmp oldByIndex newByIndexUnsorted = patchThatChangesMap oldByIndex newByIndex
214216
where newList = Map.toList newByIndexUnsorted
215217
newByIndex = Map.fromList $ zip (fst <$> newList) $ sortBy cmp $ snd <$> newList
216218

217-
-- | Create a 'PatchMapWithMove' that, if applied to the first 'Map' provided,
219+
-- | Create a t'PatchMapWithMove' that, if applied to the first 'Map' provided,
218220
-- will produce the second 'Map'.
219221
patchThatChangesMap :: (Ord k, Ord v) => Map k v -> Map k v -> PatchMapWithMove k v
220222
patchThatChangesMap oldByIndex newByIndex = PatchMapWithMove' $
@@ -260,6 +262,7 @@ instance Foldable (NodeInfo k) where
260262
instance Traversable (NodeInfo k) where
261263
traverse = bitraverseNodeInfo pure
262264

265+
-- | Like 'Data.Bitraversable.bitraverse'
263266
bitraverseNodeInfo
264267
:: Applicative f
265268
=> (k0 -> f k1)
@@ -269,11 +272,11 @@ bitraverseNodeInfo fk fv = fmap NodeInfo'
269272
. PM.bitraverseNodeInfo fk (\ ~Proxy -> pure Proxy) fv
270273
. coerce
271274

272-
-- | Change the 'From' value of a 'NodeInfo'
275+
-- | Change the 'From' value of a t'NodeInfo'
273276
nodeInfoMapFrom :: (From k v -> From k v) -> NodeInfo k v -> NodeInfo k v
274277
nodeInfoMapFrom f = coerce $ PM.nodeInfoMapFrom (unFrom' . f . From')
275278

276-
-- | Change the 'From' value of a 'NodeInfo', using a 'Functor' (or
279+
-- | Change the 'From' value of a t'NodeInfo', using a 'Functor' (or
277280
-- 'Applicative', 'Monad', etc.) action to get the new value
278281
nodeInfoMapMFrom
279282
:: Functor f
@@ -283,7 +286,7 @@ nodeInfoMapMFrom f = fmap NodeInfo'
283286
. PM.nodeInfoMapMFrom (fmap unFrom' . f . From')
284287
. coerce
285288

286-
-- | Set the 'To' field of a 'NodeInfo'
289+
-- | Set the 'To' field of a t'NodeInfo'
287290
nodeInfoSetTo :: To k -> NodeInfo k v -> NodeInfo k v
288291
nodeInfoSetTo = coerce . PM.nodeInfoSetTo
289292

@@ -308,6 +311,7 @@ pattern From_Delete = From' PM.From_Delete
308311
pattern From_Move :: k -> From k v
309312
pattern From_Move k = From' (PM.From_Move k Proxy)
310313

314+
-- | Like 'Data.Bitraversable.bitraverse'
311315
bitraverseFrom
312316
:: Applicative f
313317
=> (k0 -> f k1)

0 commit comments

Comments
 (0)