Go to the first, previous, next, last section, table of contents.


Mapping Functions

A mapping function applies a function to each of a collection of objects. Jade currently has two mapping functions, mapcar and mapc.

Function: mapcar function list
Each element in the list list is individually applied to the function function. The values returned are made into a new list which is returned.

The function should be able to be called with one argument.

(mapcar '1+ '(1 2 3 4 5))
    => (2 3 4 5 6)

Function: mapc function list
Similar to mapcar except that the values returned when each element is applied to the function function are discarded. The value returned is list.

This function is generally used where the side effects of calling the function are the important thing, not the results.

The two following functions are also mapping functions of a sort. They are variants of the delete function (see section Modifying Lists) and use predicate functions to classify the elements of the list which are to be deleted.

Function: delete-if predicate list
This function is a variant of the delete function. Instead of comparing each element of list with a specified object, each element of list is applied to the predicate function predicate. If it returns t (i.e. not nil) then the element is destructively removed from list.

(delete-if 'stringp '(1 "foo" 2 "bar" 3 "baz"))
    => (1 2 3)

Function: delete-if-not predicate list
This function does the inverse of delete-if. It applies predicate to each element of list, if it returns nil then the element is destructively removed from the list.

(delete-if-not 'stringp '(1 "foo" 2 "bar" 3 "baz"))
    => ("foo" "bar" "baz")


Go to the first, previous, next, last section, table of contents.