aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/seq/src/main/clojure/clojure/contrib/seq.clj104
-rw-r--r--modules/seq/src/test/clojure/clojure/contrib/test_seq.clj92
2 files changed, 0 insertions, 196 deletions
diff --git a/modules/seq/src/main/clojure/clojure/contrib/seq.clj b/modules/seq/src/main/clojure/clojure/contrib/seq.clj
index 1bbd2110..bc130c34 100644
--- a/modules/seq/src/main/clojure/clojure/contrib/seq.clj
+++ b/modules/seq/src/main/clojure/clojure/contrib/seq.clj
@@ -30,18 +30,6 @@
(:refer-clojure :exclude [frequencies shuffle partition-by reductions partition-all group-by flatten]))
-;; 'flatten' written by Rich Hickey,
-;; see http://groups.google.com/group/clojure/msg/385098fabfcaad9b
-(defn flatten
- "DEPRECATED. Prefer clojure.core version.
- Takes any nested combination of sequential things (lists, vectors,
- etc.) and returns their contents as a single, flat sequence.
- (flatten nil) returns nil."
- {:deprecated "1.2"}
- [x]
- (filter (complement sequential?)
- (rest (tree-seq sequential? seq x))))
-
(defn separate
"Returns a vector:
[ (filter f s), (filter (complement f) s) ]"
@@ -56,46 +44,6 @@
[s]
(map vector (iterate inc 0) s))
-;; group-by written by Rich Hickey;
-;; see http://paste.lisp.org/display/64190
-(defn group-by
- "DEPRECATED. Prefer clojure.core version.
- Returns a sorted map of the elements of coll keyed by the result of
- f on each element. The value at each key will be a vector of the
- corresponding elements, in the order they appeared in coll."
- {:deprecated "1.2"}
- [f coll]
- (reduce
- (fn [ret x]
- (let [k (f x)]
- (assoc ret k (conj (get ret k []) x))))
- (sorted-map) coll))
-
-;; partition-by originally written by Rich Hickey;
-;; modified by Stuart Sierra
-(defn partition-by
- "DEPRECATED. Prefer clojure.core version.
- Applies f to each value in coll, splitting it each time f returns
- a new value. Returns a lazy seq of lazy seqs."
- {:deprecated "1.2"}
- [f coll]
- (when-let [s (seq coll)]
- (let [fst (first s)
- fv (f fst)
- run (cons fst (take-while #(= fv (f %)) (rest s)))]
- (lazy-seq
- (cons run (partition-by f (drop (count run) s)))))))
-
-(defn frequencies
- "DEPRECATED. Prefer clojure.core version.
- Returns a map from distinct items in coll to the number of times
- they appear."
- {:deprecated "1.2"}
- [coll]
- (reduce (fn [counts x]
- (assoc counts x (inc (get counts x 0))))
- {} coll))
-
;; recursive sequence helpers by Christophe Grand
;; see http://clj-me.blogspot.com/2009/01/recursive-seqs.html
(defmacro rec-seq
@@ -112,20 +60,6 @@
`(rec-seq ~binding-name (lazy-cat ~@exprs)))
-;; reductions by Chris Houser
-;; see http://groups.google.com/group/clojure/browse_thread/thread/3edf6e82617e18e0/58d9e319ad92aa5f?#58d9e319ad92aa5f
-(defn reductions
- "DEPRECATED. Prefer clojure.core version.
- Returns a lazy seq of the intermediate values of the reduction (as
- per reduce) of coll by f, starting with init."
- {:deprecated "1.2"}
- ([f coll]
- (if (seq coll)
- (rec-seq self (cons (first coll) (map f self (rest coll))))
- (cons (f) nil)))
- ([f init coll]
- (rec-seq self (cons init (map f self coll)))))
-
(defn rotations
"Returns a lazy seq of all rotations of a seq"
[x]
@@ -136,34 +70,6 @@
(iterate inc 0) x)
(list nil)))
-(defn partition-all
- "DEPRECATED. Prefer clojure.core version.
- Returns a lazy sequence of lists like clojure.core/partition, but may
- include lists with fewer than n items at the end."
- {:deprecated "1.2"}
- ([n coll]
- (partition-all n n coll))
- ([n step coll]
- (lazy-seq
- (when-let [s (seq coll)]
- (cons (take n s) (partition-all n step (drop step s)))))))
-
-(defn shuffle
- "DEPRECATED. Prefer clojure.core version.
- Return a random permutation of coll"
- {:deprecated "1.2"}
- [coll]
- (let [l (java.util.ArrayList. coll)]
- (java.util.Collections/shuffle l)
- (seq l)))
-
-(defn rand-elt
- "DEPRECATED. Prefer clojure.core/rand-nth.
- Return a random element of this seq"
- {:deprecated "1.2"}
- [s]
- (nth s (rand-int (count s))))
-
;; seq-on written by Konrad Hinsen
(defmulti seq-on
"Returns a seq on the object s. Works like the built-in seq but as
@@ -226,13 +132,3 @@
[pred coll]
(for [[idx elt] (indexed coll) :when (pred elt)] idx))
-(defn includes?
- "Returns true if coll contains something equal (with =) to x,
- in linear time. Deprecated. Prefer 'contains?' for key testing,
- or 'some' for ad hoc linear searches."
- {:deprecated "1.2"}
- [coll x]
- (boolean (some (fn [y] (= y x)) coll)))
-
-
-
diff --git a/modules/seq/src/test/clojure/clojure/contrib/test_seq.clj b/modules/seq/src/test/clojure/clojure/contrib/test_seq.clj
index eacd9b73..082d19fa 100644
--- a/modules/seq/src/test/clojure/clojure/contrib/test_seq.clj
+++ b/modules/seq/src/test/clojure/clojure/contrib/test_seq.clj
@@ -9,44 +9,6 @@
() :d [:a :b :c]
[0 2] #{:d} [:d :a :d :a]))
-;Upon further inspection, flatten behaves... wierd.
-;These tests are what passes on August 7, 2009
-(deftest test-flatten-present
- (are [expected nested-val] (= (seq/flatten nested-val) expected)
- ;simple literals
- [] nil
- [] 1
- [] 'test
- [] :keyword
- [] 1/2
- [] #"[\r\n]"
- [] true
- [] false
- ;vectors
- [1 2 3 4 5] [[1 2] [3 4 [5]]]
- [1 2 3 4 5] [1 2 3 4 5]
- [#{1 2} 3 4 5] [#{1 2} 3 4 5]
- ;sets
- [] #{}
- [] #{#{1 2} 3 4 5}
- [] #{1 2 3 4 5}
- [] #{#{1 2} 3 4 5}
- ;lists
- [] '()
- [1 2 3 4 5] `(1 2 3 4 5)
- ;maps
- [] {:a 1 :b 2}
- [:a 1 :b 2] (seq {:a 1 :b 2})
- [] {[:a :b] 1 :c 2}
- [:a :b 1 :c 2] (seq {[:a :b] 1 :c 2})
- [:a 1 2 :b 3] (seq {:a [1 2] :b 3})
- ;Strings
- [] "12345"
- [\1 \2 \3 \4 \5] (seq "12345")
- ;fns
- [] count
- [count even? odd?] [count even? odd?]))
-
(deftest test-separate
(are [test-seq] (= (seq/separate even? test-seq) [[2 4] [1 3 5]])
[1 2 3 4 5]
@@ -60,33 +22,6 @@
[[0 :a] [1 :b] [2 :c] [3 :d]] '(:a :b :c :d)
[[0 \1] [1 \2] [2 \3] [3 \4]] "1234"))
-(deftest test-group-by
- (is (= (seq/group-by even? [1 2 3 4 5])
- {false [1 3 5], true [2 4]})))
-
-;Note - this does not make sense for maps and sets, because order is expected
-(deftest test-partition-by
- (are [test-seq] (= (seq/partition-by (comp even? count) test-seq)
- [["a"] ["bb" "cccc" "dd"] ["eee" "f"] ["" "hh"]])
- ["a" "bb" "cccc" "dd" "eee" "f" "" "hh"]
- '("a" "bb" "cccc" "dd" "eee" "f" "" "hh"))
- (is (=(partition-by #{\a \e \i \o \u} "abcdefghijklm")
- [[\a] [\b \c \d] [\e] [\f \g \h] [\i] [\j \k \l \m]])))
-
-(deftest test-frequencies
- (are [expected test-seq] (= (seq/frequencies test-seq) expected)
- {\p 2, \s 4, \i 4, \m 1} "mississippi"
- {1 4 2 2 3 1} [1 1 1 1 2 2 3]
- {1 4 2 2 3 1} '(1 1 1 1 2 2 3)))
-
-;Note - this does not make sense for maps and sets, because order is expected
-;This is a key differnce between reductions and reduce.
-(deftest test-reductions
- (is (= (seq/reductions + [1 2 3 4 5])
- [1 3 6 10 15]))
- (is (= (reductions + 10 [1 2 3 4 5])
- [10 11 13 16 20 25])))
-
;Note - this does not make sense for maps and sets, because order is expected
(deftest test-rotations
(is (= (seq/rotations [1 2 3 4])
@@ -96,33 +31,6 @@
[4 1 2 3]])))
;Note - this does not make sense for maps and sets, because order is expected
-(deftest test-partition-all
- (is (= (seq/partition-all 4 [1 2 3 4 5 6 7 8 9])
- [[1 2 3 4] [5 6 7 8] [9]]))
- (is (= (seq/partition-all 4 2 [1 2 3 4 5 6 7 8 9])
- [[1 2 3 4] [3 4 5 6] [5 6 7 8] [7 8 9] [9]])))
-
-;Thanks to Andy Fingerhut for the idea of testing invariants
-(deftest test-shuffle-invariants
- (is (= (count (seq/shuffle [1 2 3 4])) 4))
- (let [shuffled-seq (seq/shuffle [1 2 3 4])]
- (is (every? #{1 2 3 4} shuffled-seq))))
-
-;Thanks to Andy Fingerhut for the idea of testing invariants
-(deftest test-rand-elt-invariants
- (let [elt (seq/rand-elt [:a :b :c :d])]
- (is (#{:a :b :c :d} elt))))
-
-;Note - this does not make sense for maps and sets, because order is expected
(deftest test-find-first
(is (= (seq/find-first even? [1 2 3 4 5]) 2))
(is (= (seq/find-first even? '(1 2 3 4 5)) 2)))
-
-(deftest test-includes
- (are [coll k] (false? (seq/includes? coll k))
- [1 2 3] 0
- [] nil
- [:a :b] :c)
- (are [coll k] (true? (seq/includes? coll k))
- [1 2 3] 1
- [:a :b] :b))