From eaedaee31aacc6541b7636d4466bcd1503f28f01 Mon Sep 17 00:00:00 2001 From: Jeremy Penner Date: Mon, 18 Mar 2013 22:06:37 -0400 Subject: [PATCH] Some more timeline helpers --- src/hottub/timeline.clj | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/hottub/timeline.clj b/src/hottub/timeline.clj index 5fdf194..d0447aa 100644 --- a/src/hottub/timeline.clj +++ b/src/hottub/timeline.clj @@ -7,11 +7,16 @@ (let [queue (or (tln clock) [])] (assoc tln clock (conj queue val)))) -(defn timeline-after [tln clock] - (if-let [kvFirst (first tln)] - (let [clockFirst (kvFirst 0)] - (if (>= (.compare (.comp tln) clock clockFirst) 0) - (recur (dissoc tln clockFirst) clock) +(defn- timeline-strip [tln clock fnget fncmpzero] + (if-let [kv (fnget tln)] + (let [clockEnd (kv 0)] + (if (fncmpzero (.compare (.comp tln) clock clockEnd) 0) + (recur (dissoc tln clockEnd) clock fnget fncmpzero) tln)) tln)) +(defn timeline-after [tln clock] (timeline-strip tln clock first >=)) +(defn timeline-before [tln clock] (timeline-strip tln clock last <=)) + +(defn timeline-last-value [tln] + (last (second (last tln))))