diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/unheard/time_object.clj | 66 |
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." |
