2 Creating and manipulating functions

 

Without too much surprise, a functional language is specifically good at providing developers with tools and syntax support for creating and composing functions. This chapter groups together the functions in the Clojure standard library that are dedicated to manipulate or generate other functions. The chapter splits them into 4 broad categories:

  1. Function Definition. A function is the fundamental unit of composition in Clojure. This section contains the main macros dedicated to declaring new functions.
  2. Higher order functions. This section describes functions and macros whose main goal is to produce new functions guided by an user defined computation or other existing definitions.
  3. Threading macros. This important group of macros gives Clojure a visually appealing syntax to describe processing pipelines.
  4. Function execution. Finally, another group of functions dedicated to manage the execution of other functions.

Other functions and macros exist that can be categorized using the same criteria, but in this initial "fundamental" chapter, we concentrate on the most important ones while others are described in other parts of the book.

2.1  Function definition

2.1.1  defn and defn-

2.1.2  fn

2.1.3  fn*

2.2  Higher order functions

2.2.1  fnil

2.2.2  comp

2.2.3  complement

2.2.4  constantly

2.2.5  identity

2.2.6  juxt

2.2.7  memfn

2.2.8  partial

2.2.9  every-pred and some-fn

2.3  Threading macros

2.3.1  ->

2.3.2  ->>

2.3.3  cond-> and cond->>

2.3.4  some->

2.3.5  some->>

sitemap