Reputation: 3568
Other than map, filter, reduce , of the numerous other functions in clojure core, which are the next set of most useful/commonly used functions that I must learn to be productive ?
Upvotes: 11
Views: 1159
Reputation: 58806
do
I think when you first use Clojure you will be using "do" all the time, just so you can get stuff done as it lets you program in an imperative way. As your knoweldge of Clojure increases you will find that your use of "do" decreases
Upvotes: 0
Reputation: 4643
reduce, cons, first, rest, loop/recur, fn and [de structuring] are my most frequently used forms. edit: oh and partition - god that's a useful function!
Upvotes: 1
Reputation: 106391
A few that I would find hard to live without:
inc
/ dec
- for loops, recursion, off-by-one fixes etc.assoc
- for updating mapscomp
- for composing higher order functionspartial
- building a higher order function with a subset of argumentsapply
- for passing a vector of arguments to a functionconj
- for adding to a collection (of any type)first
/ next
- for manipulating sequences from the head endseq
- for creating a sequence, or testing for empty sequences with (if (seq x) ...)
There are also a few special forms / macros which aren't strictly functions but you will also find pretty essential - e.g. fn
, loop/recur
, cond
, and/or
, for
, doseq
, let
etc.
Upvotes: 3
Reputation: 25269
The cheatsheet is useful: http://clojure.org/cheatsheet, and doesn't take very long to read.
Upvotes: 6
Reputation: 61081
If you go to the 4clojure problems page and search for "core-functions", you'll find a bunch that the 4clojure team finds useful. To name a few:
Upvotes: 8
Reputation: 91587
The sequence processing library is a lot of what to me makes Clojure Clojurish. This idea being to have many functions on a single datatype rather than a few functions on a few types. so I would say that learning all the sequence manipulation functions can have a huge benefit.
ps: a special shout out for for
, reductions
, and iterate
Upvotes: 5
Reputation: 10695
Your list of map, filter, and reduce covers some of the biggies, so adding to that list would probably duplicate what you already know.
One of Clojure's strengths is synchronization. I would start writing sample code to learn how to use those synchronization constructs, refs, agents, and atoms. A lot of the Clojure books cover it. I know Clojure in Action covers these quite well.
I would work with maps, though I am not specifically referring to a function, but to why maps are good in general as well as multimethods.
Finally, I would work with why you sometimes do need to use loop .. recur. The advice I have gotten over the past 1+ years has been very sound. Use it when you absolutely have to.
Upvotes: 4