Skip to content

Instantly share code, notes, and snippets.

@fbmnds
Last active December 20, 2015 10:09
Show Gist options
  • Select an option

  • Save fbmnds/6113579 to your computer and use it in GitHub Desktop.

Select an option

Save fbmnds/6113579 to your computer and use it in GitHub Desktop.
;; as pointed out by Alexander Stoddard:
;; re-invention of clojure.core/reductions
;;
(defn cum-fn
([s cfn]
(cond (empty? s) nil
(empty? (rest s)) (list (first s))
:else (lazy-seq (cons (first s) (cum-fn (first s) (rest s) cfn)))))
([x s cfn]
(cond (empty? s) nil
(empty? (rest s)) (list (cfn x (first s)))
:else (lazy-seq (cons (cfn x (first s)) (cum-fn (cfn x (first s)) (rest s) cfn))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment