Skip to content

clojure.core/apply

View this page on ClojureDocs

Type: function Added: Clojure 1.0 Examples: 18 Runnable: 14
([f args] [f x args] [f x y args] [f x y z args] [f a b c d & args])

Applies fn f to the argument list formed by prepending intervening arguments to args.

Examples

by nipra on
by Jacolyte on
by gregg-williams on
by gstamp on . May have evaluation errors.
by boxie on
by shockbob on
by Jeff Terrell on
by nbren12 on
by bsima on
by smnplk on . May have evaluation errors.
by ibercode on
by ibercode on
by hadielmougy on
by jdf-id-au on . May have evaluation errors.
by berczeck on
by jimka2001 on
by pradeepbishnoi on . May have evaluation errors.
by 0xjlanka on

Note by virajpurang

The first example on the page, does not work on the REPL. It gives the following error:

 (def *strings* ["str1" "str2" "str3"])" 

Warning: strings not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic strings or change the name.

Should this be prefixed by - "^:dynamic"?

Note by didibus

It looks like apply when used with a lazy sequence forces the realization of the first four elements.

(take 1
      (apply concat
             (repeatedly #(do
                            (println "called")
                            (range 1 10)))))

=> "called"
=> "called"
=> "called"
=> "called"

See: https://stackoverflow.com/questions/51959298/clojure-apply-that-does-not-realize-the-first-four-elements-of-a-lazy-sequence

See also


Content from the matching ClojureDocs page, with authors credited on each contribution.