Skip to content

Instantly share code, notes, and snippets.

@ordnungswidrig
Created September 15, 2010 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ordnungswidrig/580531 to your computer and use it in GitHub Desktop.
Save ordnungswidrig/580531 to your computer and use it in GitHub Desktop.
how can the multiple iteration be simplified?
;; [1 2 3 4] -> [[[] [1 2 3 4]] [[1] [2 3 4]] [[2 3] [3 4]] ... [[1 2 3 4] []]]
(defn sublists [xs]
(map (fn [i] [(take i xs) (drop i xs)])
(range (inc (count xs)))))
(defn gist-me [xs]
(map (fn [[preds succs]]
{:preds (reduce + preds) ;; image costly reduction function
:succs (reduce * (reverse succs))}) ;; imagine costly reduction function
(sublists xs)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment