Created
September 15, 2010 10:32
-
-
Save ordnungswidrig/580531 to your computer and use it in GitHub Desktop.
how can the multiple iteration be simplified?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; [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