Email or username:

Password:

Forgot your password?
Gosha

Amazing #Clojure standard library function (macro) I've never heard of, part 983:

doto
macro
Usage: (doto x & forms)
Evaluates x then calls all of the methods and functions with the
value of x supplied at the front of the given arguments.  The forms
are evaluated in order.  Returns x.

(doto (new java.util.HashMap) (.put "a" 1) (.put "b" 2))
Added in Clojure version 1.0
2 comments
Alastair M. D. Touw

@gosha I love this about Clojure. You might think it's just 'let' over 'map', and (looking at the source) it mostly is! But, some edge cases are handled, and the interface is made regular… and it's just 10 SLOC!

Gosha

@amdt Exactly! I haven't seen this quality in any other programming language so far

Go Up