apply assoc or conj -- ArityException

217 views
Skip to first unread message

Brandon Bloom

unread,
Dec 9, 2012, 4:59:18 PM12/9/12
to cloju...@googlegroups.com
Currently, the arg lists available to assoc are: ([map key val] [map key val & kvs])

And these for conj: ([coll x] [coll x & xs])

I've run into a situtation several times where I want to do (apply assoc m keyvals), but (seq keyvals) can sometimes be nil. Similarly for (apply conj coll xs). In these cases, both assoc and conj throw an ArityException because they don't have a [coll] -only signature.

I'd like it if both assoc and conj gained a ([coll] coll) method. I'd be happy to provide patches to both CLJ and CLJS, if desirable.

Has this been discussed before? (It's quite hard to search for "assoc")

Are there any reasons not to add these methods? The only thing I can think of is that (into coll xs) is idiomatic for (apply conj coll xs), but the assoc equivalent is (into coll (partition 2 xs)) which is a bit awkward.

Andy Fingerhut

unread,
Dec 9, 2012, 6:07:47 PM12/9/12
to cloju...@googlegroups.com
Brandon:

Take a look at the patch for CLJ-1103 and see if it does what you hope for:

http://dev.clojure.org/jira/browse/CLJ-1103

Andy

Brandon Bloom

unread,
Dec 9, 2012, 6:28:39 PM12/9/12
to cloju...@googlegroups.com
Precisely what I want, but even better to look across all of the related functions. I've watched that issue, thanks!
Reply all
Reply to author
Forward
0 new messages