当前位置: 首页 > 知识库问答 >
问题:

不做分块的'sequence'版本

公西宏峻
2023-03-14

我希望有一个sequence的版本,它不对32个元素进行分块。当前,此代码将输出

(def peek #(doto % (print " ")))
(def pause #(do (Thread/sleep 10)
                %))

(take 2 (->> (range 100)
             (sequence (comp (map peek)
                             (map pause)
                             (map inc)))))

;; prints 0 1 2 3 4 <..etc..> 32
;; => (0, 1)
(take 2 (->> (range 100)
             (iter-sequence  (comp (map peek)
                             (map pause)
                             (map inc)))))

;; prints 0 1
;; => (0, 1)

有办法做到这一点吗?

共有1个答案

淳于思淼
2023-03-14

我不得不改变一些东西来让它工作。第一个步骤是剪切和粘贴sequence代码,并将clojure.lang.rt/chunkiteratorseq替换为公开了公共构造函数方法的clojure.lang.iteratorseq的替代版本。

原因是clojure.lang.iteratorseq/create对L27上的iter.next()有一个检查,如果源代码阻塞,这个检查将阻塞。

(defn seqiter
  {:added "1.0"
   :static true}
  ([coll] coll)
  ([xform coll]
   (IteratorSeq.
    (TransformerIterator/create xform (clojure.lang.RT/iter coll))))
  ([xform coll & colls]
   (IteratorSeq.
    (TransformerIterator/createMulti
     xform
     (map #(clojure.lang.RT/iter %) (cons coll colls))))))
 类似资料:
  • Sequence to Sequence 来自 Google Cho et al., 2014,主要用来解决翻译、智能问答等序列型问题。Seq2Seq 由两个不同的 RNN(比如 GRU 或 LSTM)组成:一个编码器(encoder)用来处理输入,另一个解码器(decoder)用来生成输出。 参考文档 http://cn.arxiv.org/pdf/1409.3215.pdf http://da

  • Recurrent neural networks can learn to model language, as already discussed in the RNN Tutorial (if you did not read it, please go through it before proceeding with this one). This raises an interesti

  • Recurrent neural networks can learn to model language, as already discussed in the @{$recurrent$RNN Tutorial} (if you did not read it, please go through it before proceeding with this one). This raise

  • 问题内容: 我有一个问题,我无法解决。在hibernate状态下,我没有以下问题: 然后在我的schema.ddl中,我有这个: 这里没什么可看的。一切正常。但是,如果我将提供程序切换到EclipseLink,则会出现此错误: 因此,我当然会四处搜索,如果初始值为1且它应该等于分配大小,那么我会看到有关EclipseLink创建负数的一些信息。 因此,好的,因此添加“ initialValue =

  • The Sequence object provides a unified API encapsulating the notion of zero or more consecutive elements in a collection, stream, etc. Lazy evaluation Generally speaking, creating a sequence should no

  • sequence方法用于pgsql数据库指定自增序列名,其它数据库不必使用,用法为: Db::name('user') ->sequence('user_id_seq') ->insert(['name'=>'thinkphp']);