user193116
user193116

Reputation: 3568

In Clojure, what are the other most important functions in Clojure core one must master to be productive?

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

Answers (7)

yazz.com
yazz.com

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

Hendekagon
Hendekagon

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

mikera
mikera

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 maps
  • comp - for composing higher order functions
  • partial - building a higher order function with a subset of arguments
  • apply - for passing a vector of arguments to a function
  • conj - for adding to a collection (of any type)
  • first / next - for manipulating sequences from the head end
  • seq - 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

Kevin
Kevin

Reputation: 25269

The cheatsheet is useful: http://clojure.org/cheatsheet, and doesn't take very long to read.

Upvotes: 6

dbyrne
dbyrne

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:

  • group-by
  • distinct
  • reductions
  • frequencies
  • partition
  • merge-with
  • interleave
  • interpose

Upvotes: 8

Arthur Ulfeldt
Arthur Ulfeldt

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

octopusgrabbus
octopusgrabbus

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

Related Questions