Skip to content

Commit

Permalink
caveats
Browse files Browse the repository at this point in the history
  • Loading branch information
frenchy64 committed Apr 13, 2024
1 parent 12c0119 commit c22c326
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/io/github/frenchy64/fully_satisfies/head_releasing.clj
Expand Up @@ -30,7 +30,18 @@
The basic implementation trick to achieving this is to call (rest s) on the seq currently
being processed _before_ calling (f (first f)), so the strong reference to (first f)
is transferred from the higher-order function to f during the call to f."
is transferred from the higher-order function to f during the call to f.
There are potential caveats to this approach: https://clojure.org/reference/lazy#_extension_iseqs
If the underlying ISeq implementation defines rest in terms of next as in the article, then the
functions in this namespace will force two seq elements into memory simultaneously.
For example, the call below will throw an OutOfMemoryError before the fn is called because both
elements of the seq will be realized.
(map (fn [takes-75-percent-of-heap] nil)
(lazy-seq-where-rest-calls-next
(cons (->takes-75-percent-of-heap)
(lazy-seq [(->takes-75-percent-of-heap)]))))"
(:refer-clojure :exclude [every? keep keep-indexed map map-indexed mapcat not-any? not-every? some]))

(defn naive-seq-reduce
Expand Down
5 changes: 2 additions & 3 deletions src/io/github/frenchy64/fully_satisfies/uniform.clj
Expand Up @@ -17,7 +17,7 @@
new value. Returns a lazy seq of partitions. Returns a stateful
transducer when no collection is provided.
Additionally, the cornerless/partition-by transducer behaves uniformly for
Additionally, the uniform/partition-by transducer behaves uniformly for
all values (including :clojure.core/none)."
{:added "1.2"
:static true}
Expand Down Expand Up @@ -58,7 +58,6 @@
run (cons fst (take-while #(= fv (f %)) (next s)))]
(cons run (partition-by f (lazy-seq (drop (count run) s))))))))))

;;TODO figure out if this corner case is possible
(let [halt (Object.)]
(defn halt-when
"Returns a transducer that ends transduction when pred returns true
Expand All @@ -70,7 +69,7 @@
returned. If the predicate never returns true the transduction is
unaffected.
cornerless/halt-when also works uniformly for all values (including
uniform/halt-when also works uniformly for all values (including
returning a map with key :clojure.core/halt)."
{:added "1.9"}
([pred] (halt-when pred nil))
Expand Down

0 comments on commit c22c326

Please sign in to comment.