Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a bad idea to put functions in Clojure maps, like in JavaScript?

I'm new to Clojure and finding my sea legs. I was wondering whether it is considered good or bad practice, from a functional programming standpoint, to put functions in Clojure maps and then pass those maps around like quasi-objects, as is often done in JavaScript. Explanations will also be appreciated.

like image 813
dan Avatar asked Feb 10 '11 19:02

dan


2 Answers

Do it, if it makes your code shorter or easier to understand, or test, or debug.

Or if you'd just like to. Trust your judgement.

like image 56
John Lawrence Aspden Avatar answered Sep 28 '22 03:09

John Lawrence Aspden


Clojure's multimethods are essentially maps of functions, so no, it's not a bad idea at all.

like image 42
Stuart Sierra Avatar answered Sep 28 '22 03:09

Stuart Sierra