Update compound-library.md

This commit is contained in:
2023-02-06 12:18:00 +11:00
committed by GitHub
parent f686693550
commit e1f3e2791a

View File

@@ -14,6 +14,22 @@ import compound;
This function only works when self and other are matching compounds (both arrays, dictionaries or strings). It returns a new compound of that kind, with the content of `other` appended to the content of `self`. This function only works when self and other are matching compounds (both arrays, dictionaries or strings). It returns a new compound of that kind, with the content of `other` appended to the content of `self`.
## _forEach(self, func: fn)
This function takes either an array or a dictionary as the `self` argument, and a function as `func`. The argument `func` must take two arguments - the first is the index/key, and the second is the value.
```
import compound;
fn p(i, x) {
print x;
}
var a = [1, 3, 5];
a.forEach(p); //prints 1, 3, and 5 to stdout
```
## _getKeys(self: dictionary) ## _getKeys(self: dictionary)
This returns an array of all non-null keys stored within the dictionary. The order is undefined. This returns an array of all non-null keys stored within the dictionary. The order is undefined.
@@ -22,6 +38,23 @@ This returns an array of all non-null keys stored within the dictionary. The ord
This returns an array of all values with non-null keys stored within the dictionary. The order is undefined. This returns an array of all values with non-null keys stored within the dictionary. The order is undefined.
## _map(self, func: fn)
This function takes either an array or a dictionary as the `self` argument, and a function as `func`. The argument `func` must take two arguments - the first is the index/key, and the second is the value. It returns an array with the results of each call - the order of the results when called on a dictionary are undefined.
```
import compound;
fn increment(k, v) {
return v + 1;
}
var a = [1, 2, 3];
print a.map(increment); //prints [2,3,4];
```
## _toLower(self: string) ## _toLower(self: string)
This function returns a new string which is identical to the string `self`, except any uppercase letters are replaced with the corresponding lowercase letters. This function returns a new string which is identical to the string `self`, except any uppercase letters are replaced with the corresponding lowercase letters.