add reverseList

This commit is contained in:
Jeff Hykin 2024-05-25 12:29:12 -04:00
parent 1462db9587
commit df3269bfeb

View file

@ -63,6 +63,35 @@ let
fold' 0 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 Check whether something is a function or something
annotated with function args. annotated with function args.
@ -156,6 +185,7 @@ in
{ {
loadStatic = loadStatic; loadStatic = loadStatic;
foldr = foldr; foldr = foldr;
reverseList = reverseList;
isFunction = isFunction; isFunction = isFunction;
functionArgs = functionArgs; functionArgs = functionArgs;
setFunctionArgs = setFunctionArgs; setFunctionArgs = setFunctionArgs;