Help with decisions in threading macros

161 views
Skip to first unread message

Timur

unread,
Nov 3, 2015, 11:05:33 AM11/3/15
to Clojure
Hi all,

Often I need to make decisions in simple threading macros, for instance consider the following code

(->> m
       :vector
       (filterv #(= (:id %) (:id m)))
       (reduce #(and %1 %2)))

In this case, if the result of filter is empty reduce throws an exception as it expects some values. Therefore, I want to include a decision between filter and reduce for instance if empty then add false into the resulting vector. What would be the best way to achieve this? I could add a function that checks if empty then add sth into the vector but wanted to ask your opinions if there is a better way to do this.

Regards,

Timur

Atamert Ölçgen

unread,
Nov 3, 2015, 11:22:54 AM11/3/15
to clo...@googlegroups.com
Perhaps you can replace (reduce ...) with (every? true?), which works with empty collections.

--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@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+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Kind Regards,
Atamert Ölçgen

◻◼◻
◻◻◼
◼◼◼

www.muhuk.com

Erik Assum

unread,
Nov 3, 2015, 1:38:54 PM11/3/15
to clo...@googlegroups.com
some->> 

Erik. 
-- 
i farta
--

Timur Sungur

unread,
Nov 4, 2015, 11:36:50 AM11/4/15
to clo...@googlegroups.com
Thanks!!

You received this message because you are subscribed to a topic in the Google Groups "Clojure" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojure/gFgUDo0JffU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojure+u...@googlegroups.com.

Oliver Hine

unread,
Nov 5, 2015, 3:01:11 AM11/5/15
to Clojure
See also cond-> (Clojure core) and even condas-> (http://blog.juxt.pro/posts/condas.html)

Oliy

Reply all
Reply to author
Forward
0 new messages