Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
quasar
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jens Nolte
quasar
Commits
9ea5d98e
Commit
9ea5d98e
authored
4 years ago
by
Jens Nolte
Browse files
Options
Downloads
Patches
Plain Diff
Add default implementation for DeltaObservable.subscribe
parent
66503392
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/lib/Qd/Observable/Delta.hs
+14
-0
14 additions, 0 deletions
src/lib/Qd/Observable/Delta.hs
with
14 additions
and
0 deletions
src/lib/Qd/Observable/Delta.hs
+
14
−
0
View file @
9ea5d98e
...
...
@@ -6,6 +6,7 @@ import Qd.Prelude
import
Conduit
import
qualified
Data.HashMap.Strict
as
HM
import
Data.Binary
(
Binary
(
..
))
import
Data.IORef
data
Delta
k
v
=
Reset
(
HM
.
HashMap
k
v
)
|
Add
k
v
|
Change
k
v
|
Remove
k
deriving
(
Eq
,
Show
,
Generic
)
...
...
@@ -19,3 +20,16 @@ class Observable (HM.HashMap k v) o => DeltaObservable k v o | o -> k, o -> v wh
subscribeDeltaC
::
o
->
ConduitT
()
(
Delta
k
v
)
IO
()
subscribeDeltaC
=
undefined
{-# MINIMAL subscribeDelta | subscribeDeltaC #-}
observeHashMapDefaultImpl
::
forall
k
v
o
.
(
Eq
k
,
Hashable
k
)
=>
DeltaObservable
k
v
o
=>
o
->
(
HM
.
HashMap
k
v
->
IO
()
)
->
IO
SubscriptionHandle
observeHashMapDefaultImpl
o
callback
=
do
hashMapRef
<-
newIORef
HM
.
empty
subscribeDelta
o
(
deltaCallback
hashMapRef
)
where
deltaCallback
::
IORef
(
HM
.
HashMap
k
v
)
->
Delta
k
v
->
IO
()
deltaCallback
hashMapRef
delta
=
callback
=<<
atomicModifyIORef'
hashMapRef
((
\
x
->
(
x
,
x
))
.
(
applyDelta
delta
))
applyDelta
::
Delta
k
v
->
HM
.
HashMap
k
v
->
HM
.
HashMap
k
v
applyDelta
(
Reset
state
)
=
const
state
applyDelta
(
Add
key
value
)
=
HM
.
insert
key
value
applyDelta
(
Change
key
value
)
=
HM
.
insert
key
value
applyDelta
(
Remove
key
)
=
HM
.
delete
key
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment