From cd611dc99b17a72a704aa4ea437d7f8568617319 Mon Sep 17 00:00:00 2001 From: Andrew Lipscomb Date: Wed, 23 Jul 2025 11:46:02 +1000 Subject: [PATCH 1/2] Reflect missing behaviours on map in docs --- docs/higher-order-functions.md | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/docs/higher-order-functions.md b/docs/higher-order-functions.md index 95ea8bd8..9a1e128e 100644 --- a/docs/higher-order-functions.md +++ b/docs/higher-order-functions.md @@ -7,7 +7,31 @@ sidebar_label: Higher Order Functions ## `$map()` __Signature:__ `$map(array, function)` -Returns an array containing the results of applying the `function` parameter to each value in the `array` parameter. +If the input argument is an array of 2 or more elements, returns an array containing the results of applying the `function` parameter to each value in the `array` parameter. + +``` +$map([1,2,3], function($v) { $v * 2 }) +``` + +evaluates to + +``` +[ 2, 4, 6 ] +``` + +If the input argument is an array with 1 element, returns the single result of applying the `function` parameter to each value in the `array` parameter. + +``` +$map([2], function($v) { $v * 2 }) +``` + +evaluates to + +``` +4 +``` + +If the input argument is an empty array, returns `undefined` The function that is supplied as the second parameter must have the following signature: From 389cc85872e81afd4816d90a8202cdf4bc2d370b Mon Sep 17 00:00:00 2001 From: Andrew Lipscomb Date: Thu, 24 Jul 2025 10:08:36 +1000 Subject: [PATCH 2/2] Update docs/higher-order-functions.md Co-authored-by: Matt Bailey --- docs/higher-order-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/higher-order-functions.md b/docs/higher-order-functions.md index 9a1e128e..356171f6 100644 --- a/docs/higher-order-functions.md +++ b/docs/higher-order-functions.md @@ -31,7 +31,7 @@ evaluates to 4 ``` -If the input argument is an empty array, returns `undefined` +If the input argument is an empty array, returns nothing (represented in Javascript as `undefined`) The function that is supplied as the second parameter must have the following signature: