151 | | data element of the DArray, which can have arbitrary dimensionality. Note that |

152 | | it is not possible to use this function to apply an operation for example to every |

153 | | row or column of a matrix. We will discuss how this can be done later on. |

154 | | |

155 | | {{{map:: (U.Elt a, U.Elt b, A.Shape dim) => (a -> b) -> DArray dim a -> DArray dim b}}} |

| 151 | data element of the DArray, which can have arbitrary dimensionality. |

| 152 | {{{ |

| 153 | map:: (U.Elt a, U.Elt b, A.Shape dim) => (a -> b) -> DArray dim a -> DArray dim b |

| 154 | }}} |

| 281 | == `Nesting' Array Functions == |

| 282 | |

| 283 | We already introduced the `map` function, which applies a given function to all data elements |

| 284 | of an array: |

| 285 | {{{ |

| 286 | map:: (U.Elt a, U.Elt b, A.Shape dim) => (a -> b) -> DArray dim a -> DArray dim b |

| 287 | }}} |

| 288 | We can't use `map`, however, to apply a function to all columns, rows, or other sub-arrays of |

| 289 | a multidimensional array, and generalising `map` to be able to handle this wouldn't make sense |

| 290 | in this framework. Consider, for example, a function `filter`, which takes a one-dimensional |

| 291 | array and creates a new array containing only the even elements of the argument array. If we mapped |

| 292 | this function over all the rows of a two-dimensional array, the resulting structure would, in general, |

| 293 | not be a two dimensional array anymore, since each row might potentially have a different length. |

| 294 | Therefore, we restrict the class of functions that can be mapped over sub-arrays to functions where |

| 295 | the shape of the argument determines the shape of the result. In other words, it can't depend on the data |

| 296 | values. |

| 297 | |

| 298 | |

| 299 | |