On Thu, Jan 13, 2011 at 3:18 AM, Saul Hazledine <shaz...@gmail.com> wrote:
> Hello,
>  I've never used monads but I have a problem that feels like it could
> be solved elegantly with them.
>
>  I have a sequence of functions of arbitary size and an input sequence
> s. Each function is given a sequence and returns a sequence that can
> be bigger than the input sequence. I want the output of one function
> to be operated on using a mapcat of the next function:
>
>    (let [seq-of-fns [f1 f2 f3 ... fm]]
>         (mapcat fm ... (mapcat f2 (mapcat f1 s)))
>
> If any of the functions return nil, I'd like the computation to stop.

I don't see any real reason not to use

(reduce #(if %1 (mapcat %2 %1)) s seq-of-fns)

unless you have another requirement you haven't told us.

-- 
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 group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to