From 4bd99a4b68b3b3cd0aa18ffa3841afe4486d0a9e Mon Sep 17 00:00:00 2001 From: Jim Duey Date: Wed, 26 Jan 2011 13:33:13 -0800 Subject: [PATCH] Fix-up a-except --- project.clj | 12 ++++++++++-- src/conduit/core.clj | 32 ++++++++++++++++---------------- test/conduit/test_core.clj | 18 +++++++++++++++--- 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/project.clj b/project.clj index dbc3e87..8340bef 100644 --- a/project.clj +++ b/project.clj @@ -1,6 +1,14 @@ -(defproject conduit "0.7.0-SNAPSHOT" +(defproject conduit "0.8.0" :description "Conduit: Stream Processing in Clojure." :dependencies [[org.clojure/clojure "1.2.0"] [org.clojure/clojure-contrib "1.2.0"] - [arrows "1.2.0"]] + [arrows "1.2.0"] + [swank-clojure "1.2.1"]] + :dev-dependencies [[swank-clojure "1.2.1"] + [org.clojars.technomancy/clj-stacktrace + "0.2.1-20101126.163600-6"] + [lein-difftest "1.3.2-20101010.033133-1" + :exclusions [clj-stacktrace]] + [lein-release "1.1.1"] + [lein-fail-fast "1.0.0"]] :repositories {"lambda" "http://lambda.sa2s.us/snapshots/"}) diff --git a/src/conduit/core.clj b/src/conduit/core.clj index 59166b1..64a5557 100644 --- a/src/conduit/core.clj +++ b/src/conduit/core.clj @@ -342,22 +342,22 @@ (apply a-select vp-pairs))) (defn a-except [p catch-p] - (assoc (a-comp - {:parts (:parts p) - :reply (partial (fn a-except [f x] - (try - (let [[new-x new-f] (f x)] - [[['_ (first new-x)]] - (partial a-except new-f)]) - (catch Exception e - [[[Exception [e x]]] - (partial a-except f)]))) - (:reply p))} - (a-select - Exception catch-p - '_ pass-through)) - :created-by :a-except - :args [p catch-p])) + (letfn [(a-except [f catch-f x] + (try + (let [[new-x new-f] (f x)] + [new-x (partial a-except new-f catch-f)]) + (catch Exception e + (let [[new-x new-catch] (catch-f [e x])] + [new-x (partial a-except f new-catch)]))))] + {:parts (:parts p) + :reply (partial a-except + (:reply p) + (:reply catch-p)) + :no-reply (partial a-except + (:no-reply p) + (:no-reply catch-p)) + :created-by :a-except + :args [p catch-p]})) (defn conduit-do [p & [v]] (a-arr (fn [x] diff --git a/test/conduit/test_core.clj b/test/conduit/test_core.clj index 29752e5..ec626ff 100644 --- a/test/conduit/test_core.clj +++ b/test/conduit/test_core.clj @@ -420,13 +420,27 @@ (let [te (a-arr (fn [x] (when (even? x) (throw (Exception. "An even int"))) - (* 2 x)))] + (* 2 x))) + x (assoc te + :no-reply (fn this-fn [_] + [[2] this-fn]) + :reply (fn this-fn [_] + [[1] this-fn])) + tx (a-except x (a-arr (constantly nil)))] (is (thrown? Exception (conduit-map te (range 5)))) (is (= [nil 2 nil 6 nil] (conduit-map (a-except te (a-arr (constantly nil))) + (range 5)))) + (is (= (repeat 5 2) + (conduit-map tx + (range 5)))) + + #_(is (= [] + (conduit-map (a-comp (a-all tx tx) + pass-through) (range 5)))))) (deftest test-test-conduit @@ -457,5 +471,3 @@ [-1 0 1 2 3]] (conduit-map make-and-dec (range 6))))) - -(run-tests)