WIP add a couple of types for working with patches#357
WIP add a couple of types for working with patches#357danbornside wants to merge 3 commits intodevelopfrom
Conversation
| mergeWithKey f g fg = \xs ys -> DMap.mapMaybeWithKey onlyThat $ DMap.unionWithKey doIt (DMap.map This1 xs) (DMap.map That1 ys) | ||
| where | ||
| doIt _ (This1 xs) (That1 ys) = These1 xs ys | ||
| doIt _ _ _ = error "mergeWithKey misalligned keys" |
06fc958 to
648d192
Compare
| -- | A set of changes to a 'DMap'. Any element may be inserted/updated or deleted. | ||
| -- Insertions are represented as @'ComposeMaybe' (Just value)@, | ||
| -- while deletions are represented as @'ComposeMaybe' Nothing@. | ||
| newtype PatchDMapWithReset k p = PatchDMapWithReset { unPatchDMapWithReset :: DMap k (By p) } |
There was a problem hiding this comment.
I don't see the connection with ComposeMaybe? Leftover from vanilla PatchDMap?
There was a problem hiding this comment.
The name "WithReset" - what is "Reset" in this case?
I think there's a need for this type (also for normal Map), I've seen a few instances of this type in different places...
There was a problem hiding this comment.
I also didn't know what Reset meant. Even if it has some precedence somewhere out there, the fact that none of us understand it means we should probably change it.
| inserts k = has @(Patches1Locally p) k $ \case | ||
| By_Insert x -> Just x | ||
| By_Delete -> Nothing | ||
| By_Patch _ -> Nothing |
There was a problem hiding this comment.
What to do when the patch is invalid? Is it better to call error (which seems kind of ugly... )?
The use of Maybe as documented seems to be more about Patches which don't cause any updates, rather than for error handling - I guess this is the only sensible thing to do though?
There was a problem hiding this comment.
when is a patch invalid?
There was a problem hiding this comment.
For example when applying a patch "By_Patch" to a key which doesn't exist...
Co-Authored-By: Alexandre Esteves <2335822+alexfmpe@users.noreply.github.com>
57942a9 to
732cb14
Compare
|
Superceded by reflex-frp/patch#2 |
Patchable generalizes PatchMap/SemiMap to any patchable type.
PatchDMapWithReset allows to use patches in keys. I didn't also solve the
WithMovepart since that adds significant typelevel overhead I didn't happen to need.