Olek - You may find some of the convience functions you are missing in the Tupelo library. In particular:
https://github.com/cloojure/tupelo#convenience-in-testing-seqs https://github.com/cloojure/tupelo#keeping-it-simple-with-not-nil Keeping It Simple with not-nil? Clojure has the build-in function some to return the first *truthy value* from a *sequence* argument. It also has the poorly named function some? which returns the *value* true if a *scalar* argument satisfies (not (nil? arg)). It is easy to confuse someand some?, not only in their return type but also in the argument they accept (sequence or scalar). In keeping with the style for other basic test functions, we provide the function not-nil? as the opposite of nil?. The unit tests show how not-nil? leads to a more natural code syntax: (let [data [true :a 'my-symbol 1 "hello" \x false nil] ] (let [notties (keep-if not-nil? data) nillies (drop-if not-nil? data) ] (is (and (= notties [true :a 'my-symbol 1 "hello" \x false] ) (= nillies [nil] ))) (is (every? not-nil? notties)) ; the 'not' can be used (is (not-any? nil? notties))) ; in either first or 2nd positon (let [count-if (comp count keep-if) ] (let [num-valid-1 (count-if some? data) ; awkward phrasing, doesn't feel natural num-valid-2 (count-if not-nil? data) ; matches intent much better num-nil (count-if nil? data) ] ; intent is plain (is (and (= 7 num-valid-1 num-valid-2 ) (= 1 num-nil)))))) Enjoy! Alan On Sat, Jun 18, 2016 at 5:56 PM, James Reeves <ja...@booleanknot.com> wrote: > On 19 June 2016 at 00:07, Olek <aleksander.nas...@gmail.com> wrote: >> >> Now lets talk about "difficulties" which I have found. >> For example when we talk about removing element from collection. >> >> Why there is no one operation which could behave the same for set, >> vector, list, string, and map? Let the community talk by themselves: >> http://stackoverflow.com/questions/28844647/why-are-disj-and-dissoc-distinct-functions-in-clojure >> > > I guess the difference is intent, but you'd have to ask Rich. > > >> Why there is no one operation for checking if an element is in a >> collection/keys of map/string? >> >> http://stackoverflow.com/questions/3249334/test-whether-a-list-contains-a-specific-value-in-clojure >> > > You can use "some" to achieve this effect for most collections. Maps are a > little tricky, because you could be checking for the existence of a key, a > value, or a key-value pair. > > It might be nice to have an "includes?" function, though, particularly one > that was more efficient. > > >> There is no even simple method for saying that element is not a nil. This >> requires from me the (not (nil? %)) combo. >> > > There is. "clojure.core/some?" is the same as #(not (nil? #)). > > - 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 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.