Another option that I've been using a bit recently is:

(->> [(if some-condition? some-thing)
      (if some-other-condition? some-other-thing)
      ...]
     (filterv (complement nil?)))

Which when the list of expressions is long (more than 3-4 or so) is the
most readable alternative I've come up with.

Cheers,
Colin


On 22 May 2014 09:50, Colin Yates <colin.ya...@gmail.com> wrote:

> Thanks Herwig, cond-> looks just the ticket.
>
> Off the read the core API again :).
>
> On Wednesday, 21 May 2014 17:49:11 UTC+1, Herwig Hochleitner wrote:
>
>> I like to build more complex sequences within the sequence monad, like
>> this:
>>
>> (concat
>>   (when cond1 [start elements])
>>   main-seq
>>   (when cond2 [end elements]))
>>
>> This also composes nicely with function calls.
>>
>> Another option for a subset of cases:
>>
>> (cond-> start-vec
>>   condition1 (conj end-element1)
>>   condition2 (conj end-element2))
>>
>> kind regards
>>
>>
>> 2014-05-21 18:23 GMT+02:00 Colin Yates <colin...@gmail.com>:
>>
>>> I often find myself doing the following:
>>>
>>> (let [some-seq []
>>>       some_seq (if some-condition? (conj some-seq some-element) some-seq)
>>>       some_seq (if some-other-condition? (conj some-seq
>>> some-other-element) some-seq)
>>>       some_seq etc.])
>>>
>>> In other words building up a sequence which contains the results of
>>> predicated elements.  Building up a where clause in SQL for example.
>>>
>>> I experimented with the -> and ->> but that didn't help and just looked
>>> messier.
>>>
>>> How do you handle this pretty common use case?
>>>
>>> Thanks!
>>>
>>>
>>>
>>> --
>>> 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.
>>>
>>
>>  --
> 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
> ---
> 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+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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
--- 
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to