From c03e798356b65a1f026ee2b1cc4bff872e8b204d Mon Sep 17 00:00:00 2001 From: "Clinton N. Dreisbach" Date: Fri, 10 Jan 2014 16:09:56 -0500 Subject: [PATCH] Added docs for apply --- docs/language/api.rst | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/docs/language/api.rst b/docs/language/api.rst index cd57464..30cfeb4 100644 --- a/docs/language/api.rst +++ b/docs/language/api.rst @@ -97,6 +97,31 @@ appends it as the last argument. The following code demonstrates this: 5 10 +apply +----- + +`apply` is used to apply a list of arguments and an optional dictionary of +kwargs to a function. + +Usage: `(apply fn-name args [kwargs])` + +Examples: + +.. code-block:: clj + + (defn total-purchase [price amount &optional [fees 1.05] [vat 1.1]] + (* price amount fees vat)) + + (apply total-purchase [10 15]) + ;=> 173.25 + + (apply total-purchase [10 15] {"vat" 1.05}) + ;=> 165.375 + + (apply total-purchase [] {"price" 10 "amount" 15 "vat" 1.05}) + ;=> 165.375 + + and ---