From df3269bfeb4d5bbbd012f77f48b5f48e291cc470 Mon Sep 17 00:00:00 2001 From: Jeff Hykin Date: Sat, 25 May 2024 12:29:12 -0400 Subject: [PATCH] add reverseList --- nodes/1_lib/source/detangled/1_foundation.nix | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/nodes/1_lib/source/detangled/1_foundation.nix b/nodes/1_lib/source/detangled/1_foundation.nix index 735f03a..1898b5b 100644 --- a/nodes/1_lib/source/detangled/1_foundation.nix +++ b/nodes/1_lib/source/detangled/1_foundation.nix @@ -63,6 +63,35 @@ let fold' 0 ); + /** + Reverse the order of the elements of a list. + + # Inputs + + `xs` + + : 1\. Function argument + + # Type + + ``` + reverseList :: [a] -> [a] + ``` + + # Examples + :::{.example} + ## `lib.lists.reverseList` usage example + + ```nix + reverseList [ "b" "o" "j" ] + => [ "j" "o" "b" ] + ``` + + ::: + */ + reverseList = xs: + let l = builtins.length xs; in builtins.genList (n: builtins.elemAt xs (l - n - 1)) l; + /** Check whether something is a function or something annotated with function args. @@ -156,6 +185,7 @@ in { loadStatic = loadStatic; foldr = foldr; + reverseList = reverseList; isFunction = isFunction; functionArgs = functionArgs; setFunctionArgs = setFunctionArgs;