LazyTransformer

typeremoved v1.9.562added v0.0-2301Edit
satisfies ICollection IEmptyableCollection IEquiv IHash IMeta INext IPending IPrintWithWriter ISeq ISeqable ISequential IWithMeta

(LazyTransformer. stepper first rest meta)

Source code @ clojurescript:src/main/cljs/cljs/core.cljs
(deftype LazyTransformer [^:mutable stepper ^:mutable first ^:mutable rest meta]
  Object
  (indexOf [coll x]
    (-indexOf coll x 0))
  (indexOf [coll x start]
    (-indexOf coll x start))
  (lastIndexOf [coll x]
    (-lastIndexOf coll x (count coll)))
  (lastIndexOf [coll x start]
    (-lastIndexOf coll x start))

  IWithMeta
  (-with-meta [this new-meta]
    (LazyTransformer. stepper first rest new-meta))

  IMeta
  (-meta [this] meta)

  ICollection
  (-conj [this o]
    (cons o (-seq this)))

  IEmptyableCollection
  (-empty [this]
    ())

  ISequential
  IEquiv
  (-equiv [this other]
    (let [s (-seq this)]
      (if-not (nil? s)
        (equiv-sequential this other)
        (and (sequential? other)
             (nil? (seq other))))))

  IHash
  (-hash [this]
    (hash-ordered-coll this))

  ISeqable
  (-seq [this]
    (when-not (nil? stepper)
      (.step stepper this))
    (if (nil? rest)
      nil
      this))

  ISeq
  (-first [this]
    (when-not (nil? stepper)
      (-seq this))
    (if (nil? rest)
      nil
      first))

  (-rest [this]
    (when-not (nil? stepper)
      (-seq this))
    (if (nil? rest)
      ()
      rest))

  INext
  (-next [this]
    (when-not (nil? stepper)
      (-seq this))
    (if (nil? rest)
      nil
      (-seq rest)))

  IPending
  (-realized? [_]
    (nil? stepper)))