On Nov 9, 2:47 pm, Shoeb Bhinderwala shoeb.bhinderw...@gmail.com
wrote:
([a] [a b] [a b c] [a b c d])
It should be pointed out that this result -- while it may be what you
actually want -- is not all subsets of [a b c d]. For that
you might want to use combinatorics/subsets:
user= (C/subsets [a
Is there a more elegant/idomatic way to achieve the following result:
user= a1
[a b c d]
user= (map-indexed (fn [n x] (vec (take (inc n) x))) (take (count a1)
(repeat a1)))
([a] [a b] [a b c] [a b c d])
--
You received this message because you are subscribed to the Google
Groups Clojure group.
(map #(vec (take (inc %) a1)) (range (count a1)))
does it the lovely map.
/Linus
2011/11/9 Shoeb Bhinderwala shoeb.bhinderw...@gmail.com
Is there a more elegant/idomatic way to achieve the following result:
user= a1
[a b c d]
user= (map-indexed (fn [n x] (vec (take (inc n) x))) (take
Does Clojure have the equivalent of Haskell's 'scan' function? (I am on my
phone...) Seems like a solution with that would be nice. (scan is like
reduce except it keeps all intermediate results)
On Nov 9, 2011 5:57 PM, Linus Ericsson oscarlinuserics...@gmail.com
wrote:
(map #(vec (take (inc %)
Another way to do it, using 'reductions':
(rest (reductions conj [] a1))
On Wednesday, November 9, 2011 5:47:08 PM UTC-5, Shoeb Bhinderwala wrote:
Is there a more elegant/idomatic way to achieve the following result:
user= a1
[a b c d]
user= (map-indexed (fn [n x] (vec (take (inc n)
That's exactly what 'reductions' does :)
On Wednesday, November 9, 2011 6:09:08 PM UTC-5, Alex Baranosky wrote:
Does Clojure have the equivalent of Haskell's 'scan' function? (I am on my
phone...) Seems like a solution with that would be nice. (scan is like
reduce except it keeps all
Dang,
I just logged in in-flight just so I could post my solution with reductions
:)
(defn doit [coll]
(rest (reductions conj [] coll)))
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to clojure@googlegroups.com
Or my current favorite take-while iterate combo:
C:\clojure-1.2.0java -jar clojure.jar
Clojure 1.2.0
user= (take-while seq (iterate rest [1 2 3 4]))
([1 2 3 4] (2 3 4) (3 4) (4))
user= (take-while seq (iterate butlast [1 2 3 4]))
([1 2 3 4] (1 2 3) (1 2) (1))
user=
On Nov 9, 4:52 pm, Alex