From e1c825dd244472773e78eac5de2b175dc8fa60ab Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Sat, 11 Feb 2023 04:05:41 +1100 Subject: [PATCH] Added a few functions --- compound-library.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/compound-library.md b/compound-library.md index 87ba5c0..2957ff2 100644 --- a/compound-library.md +++ b/compound-library.md @@ -14,9 +14,21 @@ 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`. +## _containsKey(self: dictionary, key) + +This function returns `true` if `self` contains the given `key`, otherwise it returns false. + +## _containsValue(self, value) + +This function returns `true` if `self` contains the given `value`, otherwise it returns false. + +## _every(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 of the array/dictionary, and the second is the value. The contents of `self` are passed into `func`, one element at a time, until `func` returns `false`, at which point this function returns `false`. Otherwise this function returns `true`. + ## _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 of the array/dictionary, and the second is the value. +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 of the array/dictionary, and the second is the value. The contents of `self` are passed into `func`, one element at a time. ``` import compound; @@ -30,6 +42,10 @@ var a = [1, 3, 5]; a.forEach(p); //prints 1, 3, and 5 to stdout ``` +## _filter(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 of the array/dictionary, and the second is the value. The contents of `self` are passed into `func`, one element at a time, and the function returns a new compound for every element that `func` returned a truthy value for. + ## _getKeys(self: dictionary) This returns an array of all non-null keys stored within the dictionary. The order is undefined. @@ -70,6 +86,10 @@ var a = [1, 2, 3, 4]; print a.reduce(0, f); //prints "10" ``` +## _some(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 of the array/dictionary, and the second is the value. The contents of `self` are passed into `func`, one element at a time, until `func` returns `true`, at which point this function returns `true`. Otherwise this function returns `false`. + ## _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.