Documented some more core functions
All checks were successful
Build / build (push) Successful in 1m52s

This commit is contained in:
Leon Mika 2025-01-19 09:33:09 +11:00
parent 531dd9bf4e
commit 80e56ec1a5

View file

@ -23,13 +23,13 @@ Displays the string representation of ARGS to stdout followed by a new line.
### foreach ### foreach
``` ```
foreach SEQ BLOCK foreach COL BLOCK
``` ```
Iterates BLOCK over every element of the sequence. Iterates BLOCK over every element of the sequence.
The values pass to BLOCK will depend on the type of SEQ. If SEQ is a list, BLOCK receives the element value. The values pass to BLOCK will depend on the type of COL. If COL is a list, BLOCK receives the element value.
If SEQ is a hash, BLOCK receives both the key and value of each element. If COL is a hash, BLOCK receives both the key and value of each element.
BLOCK can call `break` and `continue` which will exit out of the loop, or jump to the start of the next iteration BLOCK can call `break` and `continue` which will exit out of the loop, or jump to the start of the next iteration
respectively. respectively.
@ -46,6 +46,14 @@ foreach [a:"one" b:"two"] { |k v|
} }
``` ```
## index
```
index COL [INDEX...]
```
Returns the index value at INDEX of COL. COL can be either a list or a hash.
### keys ### keys
``` ```
@ -58,20 +66,20 @@ If HASH is not a hash, then nil will be returned.
### len ### len
``` ```
len SEQ len COL
``` ```
Returns the length of SEQ. If SEQ is a list or hash, SEQ will be the number of Returns the length of COL. If COL is a list or hash, COL will be the number of
elements. If SEQ is a string, SEQ will be the string's length. All other values will elements. If COL is a string, COL will be the string's length. All other values will
return a length of 0. return a length of 0.
### map ### map
``` ```
map SEQ BLOCK map COL BLOCK
``` ```
Returns a new list of elements mapped from SEQ according to the result of BLOCK. SEQ can be any listable data Returns a new list of elements mapped from COL according to the result of BLOCK. COL can be any listable data
structure, however the result will always be a concrete list. structure, however the result will always be a concrete list.
``` ```
@ -92,20 +100,43 @@ When NAME is set, this function defining a function a name will always declare i
### reduce ### reduce
``` ```
reduce SEQ [INIT] BLOCK reduce COL [INIT] BLOCK
``` ```
Returns the result of reducing the elements of SEQ with the passed in block. Returns the result of reducing the elements of COL with the passed in block.
BLOCK will receive at least two argument, with the current value of the accumulator always being the last argument. BLOCK will receive at least two argument, with the current value of the accumulator always being the last argument.
If SEQ is a list, the arguments will be _|element accumulator|_, and if SEQ is a hash, the arguments will be If COL is a list, the arguments will be _|element accumulator|_, and if COL is a hash, the arguments will be
_|key value accumulator|_. _|key value accumulator|_.
The block result will be set as the value of the accumulator for the next iteration. Once all elements are process The block result will be set as the value of the accumulator for the next iteration. Once all elements are process
the accumulator value will be returned as the result of `reduce`. the accumulator value will be returned as the result of `reduce`.
If INIT is not set, and SEQ is a list, the accumulator will be set to the first value and BLOCK will be called If INIT is not set, and COL is a list, the accumulator will be set to the first value and BLOCK will be called
from the second element, if any. If SEQ is a hash, then the accumulator will be set to nil. from the second element, if any. If COL is a hash, then the accumulator will be set to nil.
## seq
```
seq [FROM] TO [-inc]
```
Returns a listable sequence containing all the integers from 0 to TO, exclusive.
TO can be either be negative or positive. If TO Is positive, then the sequence will
step by +1; if TO is negative, then the sequence will step by -1.
If FROM is specified, then the collection contains all the integers from FROM inclusive, to TO
exclusive. The step will be +1 or -1 if TO is greater than, or less than FROM respectively.
If FROM and TO are equal, or if FROM is unspecified and TO is 0, then the sequence will be empty.
If -inc is specified, then the sequence will step towards TO inclusively.
```
foreach (seq 5) { |i|
echo $i
}
```
### set ### set