Permalink
Browse files

Kill separate-by in favor of separate

  • Loading branch information...
1 parent a26dc27 commit 1f1ee158e8a2a046c7633aa86add78bcafee31b8 @marick committed Jan 26, 2013
@@ -127,11 +127,8 @@ metadata (as provided by def) merged into the metadata of the original."
;;; Sequences
-(defn separate-by
- "Like clojure.core/separate, but not lazy, returns nil for empty list."
- [predicate forms]
- (let [group (group-by (strictly predicate) forms)]
- [ (group true) (group false) ]))
+
+;;; Also pull in set operations
(defn rotations
"Returns a lazy seq of all rotations of a seq"
@@ -95,7 +95,7 @@
(if (nil? root-to-handle)
surviving-namespaces
(let [actual-dependent-set (set (get-in state-tracker [deps-key :dependents root-to-handle]))
- [new-roots unkilled-descendents] (separate-by actual-dependent-set surviving-namespaces)]
+ [new-roots unkilled-descendents] (separate actual-dependent-set surviving-namespaces)]
(recur (concat roots-to-handle-later new-roots)
unkilled-descendents))))))
@@ -98,18 +98,18 @@
(macroexpand-1 (map-first #(symbol "midje.parsing.1-to-explicit-form.background" (name %)) state-description))
wrapping-target))
-(letfn [(background-fake-wrappers [fakes]
+(letfn [(background-fake-wrappers [fake-maker-forms]
(let [around-facts-and-checks `(with-pushed-namespace-values
:midje/background-fakes
- ~fakes ~(unify/?form))]
+ [~@fake-maker-forms] ~(unify/?form))]
(list
(with-wrapping-target around-facts-and-checks :facts))))]
;; Collecting all the background fakes is here for historical reasons:
;; it made it easier to eyeball expanded forms and see what was going on.
(defn background-wrappers [background-forms]
(predefine-metaconstants-from-form background-forms)
- (let [[fakes state-descriptions] (separate-by fakes/fake? (extract-state-descriptions+fakes background-forms))
+ (let [[fakes state-descriptions] (separate fakes/fake? (extract-state-descriptions+fakes background-forms))
state-wrappers (eagerly (map state-wrapper state-descriptions))]
(if (empty? fakes)
state-wrappers
@@ -59,6 +59,6 @@
(defn to-lexical-map-form [full-form]
(domonad validate-m [[call-form arrow expected-result & fakes+overrides] (validate full-form)
- [fakes overrides] (separate-by a-fake? fakes+overrides)
+ [fakes overrides] (separate a-fake? fakes+overrides)
_ (validate fakes)]
- (expect-expansion call-form arrow expected-result fakes overrides)))
+ (expect-expansion call-form arrow expected-result (vec fakes) overrides)))
@@ -11,7 +11,7 @@
;;; Print levels (keywords)
(defn separate-print-levels [args default]
- (let [[[print-level & extras] non-levels] (separate-by levels/valids args)]
+ (let [[[print-level & extras] non-levels] (separate levels/valids args)]
(when (seq extras)
(throw (user-error "You have extra print level names or numbers.")))
(dorun (map levels/validate-level! (filter number? args)))
@@ -46,9 +46,9 @@
(defn separate-filters
([args plain-argument?]
(let [[filters remainder]
- (separate-by #(and (not (plain-argument? %))
- ((form/any-pred-from [string? regex? fn? keyword?]) %))
- args)]
+ (separate #(and (not (plain-argument? %))
+ ((form/any-pred-from [string? regex? fn? keyword?]) %))
+ args)]
[filters
(desired-fact-predicate-from filters)
remainder]))
@@ -72,11 +72,6 @@
;;; Sequences
-(fact "divide seq into two seqs: items that pass a predicate and a items the fail"
- (separate-by odd? [1 2 3]) => [ [1 3] [2] ]
- "works for predicates that don't return true or false"
- (separate-by #(if (odd? %) nil %) [1 2 3]) => [[2] [1 3]])
-
(fact
(map-first str [1 2 3]) => ["1" 2 3])
@@ -34,24 +34,24 @@
(fact "separating overrides of an #expect from fakes"
;; The lets are because fact isn't smart enough not to add overrides to fake call otherwise.
- (let [actual (separate-by a-fake? '( (fake (f 1) => 2) :key 'value))]
+ (let [actual (separate a-fake? '( (fake (f 1) => 2) :key 'value))]
actual => [ '[(fake (f 1) => 2)]
'[:key 'value] ])
- (let [actual (separate-by a-fake? '( (not-called some-function) :key 'value))]
+ (let [actual (separate a-fake? '( (not-called some-function) :key 'value))]
actual => [ '[(not-called some-function)]
'[:key 'value] ])
;; often passed a seq.
- (let [actual (separate-by a-fake? (seq '( (fake (f 1) => 2) :key 'value)))]
+ (let [actual (separate a-fake? (seq '( (fake (f 1) => 2) :key 'value)))]
actual => [ '[(fake (f 1) => 2)]
'[:key 'value] ])
- (let [actual (separate-by a-fake? '())]
+ (let [actual (separate a-fake? '())]
actual => (just empty? empty?))
"data fakes too"
- (let [actual (separate-by a-fake? '((data-fake ..m.. =contains=> {:a 1}) :key 'value))]
+ (let [actual (separate a-fake? '((data-fake ..m.. =contains=> {:a 1}) :key 'value))]
actual => [ '[(data-fake ..m.. =contains=> {:a 1})]
'[:key 'value] ]))
@@ -6,10 +6,10 @@
(facts "separating levels out of argument lists"
(separate-print-levels [] :print-normally)
- => [ [] :print-normally nil ]
+ => [ [] :print-normally [] ]
(separate-print-levels [:print-nothing] ..irrelevant..)
- => [[:print-nothing] :print-nothing nil]
+ => [[:print-nothing] :print-nothing []]
(separate-print-levels [:all :print-nothing] ..irrelevant..)
=> [[:print-nothing] :print-nothing [:all]]

0 comments on commit 1f1ee15

Please sign in to comment.