Hi Dave,
You can use reduce for this job, and have the reducing function return a
(reduced retval) when you want to break out.
Cheers,
Stu
On Sun, Nov 24, 2013 at 11:19 AM, David Simmons shortlypor...@gmail.comwrote:
Hi All.
Still struggling to get my head around Clojure - this is attempt
Another option is to take-while the values in the sequence are valid, and
then map over the ones that are.
- James
On 24 November 2013 16:50, Stuart Halloway stuart.hallo...@gmail.comwrote:
Hi Dave,
You can use reduce for this job, and have the reducing function return a
(reduced retval)
Hi Stu
I understand Reduce but can't quite see how this would work. Don't suppose
you'd have a simple example would you?
Many thanks
Dave
--
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to
On Nov 24, 2013, at 10:19 , David Simmons shortlypor...@gmail.com wrote:
I wish to process each item in a vector. I know I can use map to do this e.g.
(map my-func my-vector). My problem is that I need to be able to break out of
the map if my-func returns an error when processing any of the
@James - I'll take a look at take-while
@Michael - I thought using exceptions to break out of a stuff was
considered bad practice?
cheers
Davew
--
--
You received this message because you are subscribed to the Google
Groups Clojure group.
To post to this group, send email to
Something like:
(defn safe-sum [coll]
(reduce (fn [s x] (if x (+ x s) (reduced s))) coll))
This will compute the sum until it hits a falsey (i.e. nil or false)
value. Alternatively, you could write it:
(defn safe-sum [coll]
(apply + (take-while identity coll)))
- James
On 24 November
Many thanks James
--
--
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
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this
Hi Dave,
Another option is to use the
forhttp://clojuredocs.org/clojure_core/clojure.core/formacro's while clause
to stop processing as soon as you hit an error.
Here's a basic example with a simple my-func that returns a string-based
error to give you an idea of how it could look:
(defn
Jernau - that looks perfect. I'll give it a go.
cheers
Dave
--
--
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
Note that posts from new members are moderated - please be patient with