weavejester / medley

A lightweight library of useful Clojure functions
Eclipse Public License 1.0
865 stars 66 forks source link

Add flavours of selfmap macros for concise zipmap #21

Closed analyticbastard closed 7 years ago

analyticbastard commented 7 years ago

A repetitive patter I have come across is this

(zipmap [:a :b :c] [a b c])

which is needed to build a map as an input to a map destructuring function (or build the map manually). The bindings are very often named identically to the input map's keys.

This set of functions remove the redundancy of having to reapeat the binding symbol as a keyword and reduces the boilerplate.

Several flavours provided: the map's key types can be plain key, qualified key, string and symbol.

weavejester commented 7 years ago

Thanks for the patch, but I'm afraid macros are outside Medley's scope.

analyticbastard commented 7 years ago

Would you consider adding a macros namespace?

Otherwise, which is a medley macros equivalent ?

weavejester commented 7 years ago

No, sorry. I want Medley to have a tight focus, and the macros in your patch are outside that scope.

I'm not sure what library would be considered a "macros equivalent". Perhaps make your own?

cloojure commented 7 years ago

​Hi - There is a pair of macros for this problem in the Tupelo library. http://cloojure.github.io/doc/tupelo/tupelo.core.html#var-vals-.3Emap See vals->map and with-map-vals.

Alan

On Fri, Jun 16, 2017 at 8:39 AM, Javier Arriero notifications@github.com wrote:

A repetitive patter I have come across is this

(zipmap [:a :b :c] [a b c])

which is needed to build a map as an input to a map destructuring function (or build the map manually). The bindings are very often named identically to the input map's keys.

This set of functions remove the redundancy of having to reapeat the binding symbol as a keyword and reduces the boilerplate.

Several flavours provided: the map's key types can be plain key, qualified key, string and symbol.

You can view, comment on, or merge this pull request online at:

https://github.com/weavejester/medley/pull/21 Commit Summary

  • Add flavours of selfmap macros for concise zipmap

File Changes

Patch Links:

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/weavejester/medley/pull/21, or mute the thread https://github.com/notifications/unsubscribe-auth/AGwXB7JaKLgG2BRiLv5K649zG3zt9pQ5ks5sEqG4gaJpZM4N8nbg .