Skip to content

Commit

Permalink
incseq count
Browse files Browse the repository at this point in the history
  • Loading branch information
xificurC committed Apr 22, 2024
1 parent fa3ed0e commit 06ea0d0
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/hyperfiddle/incseq.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ successive sequence diffs. Incremental sequences are applicative functors with `
(:require [hyperfiddle.incseq.perm-impl :as p]
[hyperfiddle.incseq.diff-impl :as d]
[hyperfiddle.incseq.items-impl :as i]
[hyperfiddle.rcf :refer [tests]])
[hyperfiddle.rcf :refer [tests]]
[missionary.core :as m])
(:import #?(:clj (clojure.lang IFn IDeref))
missionary.Cancelled))

Expand Down Expand Up @@ -1231,8 +1232,25 @@ optional `compare` function, `clojure.core/compare` by default.

(def ^{:arglists '([incseq])} items i/flow)

(def ^{:arglists '([incseq])
:doc "
Returns the provided `incseq`'s size as a continuous flow
"} count*
(fn [is] (m/reductions (fn [r x] (-> r (+ (:grow x)) (- (:shrink x)))) 0 is)))

;; unit tests

(tests
(def !x (atom [:foo]))
(def ps ((count* (diff-by identity (m/watch !x))) #() #()))
@ps := 0
@ps := 1
(swap! !x conj :bar), @!x := [:foo :bar]
@ps := 2
(swap! !x pop), @!x := [:foo]
@ps := 1
(ps))

(tests "incremental sequences"
(letfn [(queue []
#?(:clj (let [q (java.util.LinkedList.)]
Expand Down

0 comments on commit 06ea0d0

Please sign in to comment.