summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJake Zerrer <him@jakezerrer.com>2025-11-14 16:13:51 -0500
committerJake Zerrer <him@jakezerrer.com>2025-11-14 16:14:12 -0500
commitb60b17e425b20d0fd0740f6e40fe47062c566a02 (patch)
treef24970513874aaf95e3c044db254b205bc4cce21
parentc9e4f877402fbadaed1e8e3a0e41125e2188b482 (diff)
More work, now on merge-tocs
-rw-r--r--src/unheard/time_object.clj66
1 files changed, 48 insertions, 18 deletions
diff --git a/src/unheard/time_object.clj b/src/unheard/time_object.clj
index 6f088b6..3556321 100644
--- a/src/unheard/time_object.clj
+++ b/src/unheard/time_object.clj
@@ -37,21 +37,18 @@
time tree is consumed at a point in time within the time-object's
interval."
[>start >end >metadata >flow]
- (let [action (atom nil)
- >action (m/watch action)
- id (swap! id-counter inc)]
- (m/ap
- (reset! action
- [:add
- id
- {:start >start
- :end >end
- :metadata >metadata
-
- :flow >flow}])
- (try
- (m/?< >action)
- (catch missionary.Cancelled _ [:remove id])))))
+ (m/ap
+ (let [id (swap! id-counter inc)]
+ (m/amb=
+ [id
+ :add
+ {:start >start
+ :end >end
+ :metadata >metadata
+ :flow >flow}]
+ (try
+ (m/? m/never)
+ (catch missionary.Cancelled _ [id :remove]))))))
(comment
(def cancel
@@ -60,6 +57,20 @@
(cancel))
+(defn with-final
+ []
+ (m/ap
+ (m/amb=
+ :start
+ (try
+ (m/? m/never)
+ (catch missionary.Cancelled _ :end)))))
+
+(defn merge-flows [& flows]
+ (m/ap
+ (m/?<
+ (m/?> (count flows) (m/seed flows)))))
+
(defn time-object-collection
"Takes a flow of [diff-action time-object-id time-object], where:
- diff-action is one of either :add or :remove
@@ -68,14 +79,16 @@
Returns a collection of time objects, represented as a flow."
[& time-objects]
- (apply m/latest vector time-objects))
+ ;; Goal: use group-by to emit just twice per time object
+ (m/ap (m/?> (try (apply m/zip vector time-objects) (catch missionary.Cancelled _)))))
(comment
(def cancel
((m/reduce prn nil
(time-object-collection
(time-object 1 2 :a (m/ap))
- (time-object 3 4 :a (m/ap)))) prn prn))
+ (time-object 3 4 :b (m/ap))
+ (time-object 5 6 :c (m/ap)))) prn prn))
(cancel))
@@ -84,7 +97,24 @@
(defn merge-tocs
"Merge multiple time-object-collections. Returns a new time-object-collection."
- [& time-object-colletion])
+ [& time-object-collections]
+ (apply merge-flows time-object-collections))
+
+(comment
+ (def cancel
+ ((m/reduce prn nil
+ (merge-tocs
+ (time-object-collection
+ (time-object 1 2 :a (m/ap))
+ (time-object 3 4 :b (m/ap))
+ (time-object 5 6 :c (m/ap)))
+ (time-object-collection
+ (time-object 1 2 :d (m/ap))
+ (time-object 3 4 :e (m/ap))
+ (time-object 5 6 :f (m/ap))))) prn prn))
+ ;; Whoa! Running cancel twice cancels twice...
+ ;; https://clojurians.slack.com/archives/CL85MBPEF/p1763154775780589?thread_ts=1763149125.436899&cid=CL85MBPEF
+ (cancel))
(defn timeline
"Primary timeline bookkeeping mehanism."