Should the completion arity of a stateful transducer reset state?

閲覧: 50 回
最初の未読メッセージにスキップ

David Bürgin

未読、
2017/07/22 15:43:232017/07/22
To: clo...@googlegroups.com
Hello all,

I found an edge case where stateful transducers in core differ in
whether they reset or clear state in the completion arity
(partition-all) or don’t (take).

Given the two transformed reducing functions

(def conj-partitioning-all-3 ((partition-all 3) conj))
(def conj-taking-3 ((take 3) conj))

when performing transduction with those reducing functions twice in a
row, one yields the same result twice, the other doesn’t.

(transduce identity conj-partitioning-all-3 [] (range 10))
;; => [[0 1 2] [3 4 5] [6 7 8] [9]]
;; => [[0 1 2] [3 4 5] [6 7 8] [9]]

(transduce identity conj-taking-3 [] (range 10))
;; => [0 1 2]
;; => []

Question: which behaviour is the one I should emulate in my own
transducers?

Thank you,
David

Timothy Baldridge

未読、
2017/07/22 16:02:282017/07/22
To: clo...@googlegroups.com
Once a transducer is completed it should never be called again. This is why transduce takes both a transducer and a reducing function and combines them internally. The thought here is that it will be harder to shoot yourself in the foot by reusing a stateful reducing function if you don't have to combine the xf with the rf manually. 

Timothy

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
“One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.”
(Robert Firth)

David Bürgin

未読、
2017/07/22 17:03:492017/07/22
To: clo...@googlegroups.com
On 22/07/17 22:02, Timothy Baldridge wrote:
> Once a transducer is completed it should never be called again.
Thank you, Timothy, this was probably obvious but I don't remember
reading it anywhere so this really helped.

David
全員に返信
投稿者に返信
転送
新着メール 0 件