| summaryrefslogtreecommitdiff |
diff options
Diffstat (limited to 'content/fate_v1/computations/collections/_index.md')
| -rw-r--r-- | content/fate_v1/computations/collections/_index.md | 243 |
1 files changed, 150 insertions, 93 deletions
diff --git a/content/fate_v1/computations/collections/_index.md b/content/fate_v1/computations/collections/_index.md index 80a4ead..584baef 100644 --- a/content/fate_v1/computations/collections/_index.md +++ b/content/fate_v1/computations/collections/_index.md @@ -2,151 +2,208 @@ title: Collections --- ### ACCESS -{{< fatecode >}}(access [INT] [COLLECTION|COLLECTION PTR]){{< /fatecode >}} +{{< fatecode >}}(list:access [INT] [LIST]){{< /fatecode >}} +{{< fatecode >}}(set:access [INT] [SET]){{< /fatecode >}} -Returns the value of the `[INT]`th element in `[COLLECTION|COLLECTION PTR]`. +Returns the value of the `[INT]`th element in the collection. ### ACCESS CONSTANT INDEX -{{< fatecode >}}[(COLLECTION|COLLECTION PTR) VAR].{Integer}{{< /fatecode >}} +{{< fatecode >}}[(LIST) VAR].{Integer}{{< /fatecode >}} +{{< fatecode >}}[(SET) VAR].{Integer}{{< /fatecode >}} -Returns a variable corresponding to the `[INT]`th element in -`[(COLLECTION|COLLECTION PTR) VAR]`. - -### ACCESS POINTER -{{< fatecode >}}(access_pointer [INT] [(COLLECTION|COLLECTION PTR) VAR]){{< /fatecode >}} - -Returns a pointer to the `[INT]`th element in `[(COLLECTION|COLLECTION PTR) -VAR]`. +Returns a variable corresponding to the `[INT]`th element in the collection. ### ADD ELEMENT AT -{{< fatecode >}}(add_element_at [INT] [COMPUTATION*] [LIST]){{< /fatecode >}} +{{< fatecode >}}(list:add_element_at [INT] [COMPUTATION*] [LIST]){{< /fatecode >}} Returns a copy of `[LIST]` with `[COMPUTATION*]` added at index `[INT]`. Note -that `[COMPUTATION*]` does not allow use of the variable shorthand. +that `[COMPUTATION*]` does not allow use of the variable shorthand if `[LIST]` +is a list of strings. ### ADD ELEMENT -{{< fatecode >}}(add_element [C0 = COMPUTATION*] ... [CN = COMPUTATION*] [COLLECTION]){{< /fatecode >}} +{{< fatecode >}}(list:add_element [C0 = COMPUTATION*] ... [CN = COMPUTATION*] [LIST]){{< /fatecode >}} +{{< fatecode >}}(set:add_element [C0 = COMPUTATION*] ... [CN = COMPUTATION*] [SET]){{< /fatecode >}} Returns a copy of `[COLLECTION]` with `C0` ... `CN` added. If `[COLLECTION]` is a `[LIST]`, then the elements are added at the end of the list, in order (meaning that `CN` will be the last element added). -Note that `[COMPUTATION*]` does not allow use of the variable shorthand. +Note that `[COMPUTATION*]` does not allow use of the variable shorthand if the +collection is a collection of strings. ### ADDING MEMBERS -{{< fatecode >}}(add_all_elements [C0 = COLLECTION] [C1 = COLLECTION]){{< /fatecode >}} +{{< fatecode >}}(list:add_all_elements [C0 = LIST|SET]+ [C1 = LIST]){{< /fatecode >}} +{{< fatecode >}}(set:add_all_elements [C0 = LIST|SET]+ [C1 = SET]){{< /fatecode >}} -Returns a copy of `[C1]`, with all the elements of `[C2]` added. If `[C1]` +Returns a copy of `[C1]`, with all the elements of `[C0]` added. If `[C1]` is a `[LIST]`, the new members are added at the end of the list. +As a shorthand, multiple `[C0]` can be specified. They will all be added in +order. + +### SUB-LIST +{{< fatecode >}}(list:sublist [start: INT] [end_before: INT] [LIST]){{< /fatecode >}} +{{< fatecode >}}(set:subset [start: INT] [end_before: INT] [SET]){{< /fatecode >}} + +Returns a copy of the collection in which only the elements with an index +higher or equal to `[start]` and strictly less than `[end_before]` are included. + +### SHUFFLE +{{< fatecode >}}(list:shuffle [LIST]){{< /fatecode >}} +{{< fatecode >}}(set:shuffle [SET]){{< /fatecode >}} + +Returns a list containing all the elements of the collection in a random order. + ### COUNT -{{< fatecode >}}(count [COMPUTATION*] [COLLECTION]){{< /fatecode >}} +{{< fatecode >}}(list:count [COMPUTATION*] [LIST]){{< /fatecode >}} +{{< fatecode >}}(set:count [COMPUTATION*] [SET]){{< /fatecode >}} -Returns the number of occurrences of `[COMPUTATION*]` in `[COLLECTION]`. -Note that `[COMPUTATION*]` does not allow use of the variable shorthand. +Returns the number of occurrences of `[COMPUTATION*]` in `[LIST]` or `[SET]`. +Note that `[COMPUTATION*]` does not allow use of the variable shorthand if +the collection is a collection of strings. ### INDEX OF -{{< fatecode >}}(index_of [COMPUTATION] [COLLECTION]){{< /fatecode >}} +{{< fatecode >}}(list:index_of [COMPUTATION] [LIST]){{< /fatecode >}} +{{< fatecode >}}(set:index_of [COMPUTATION] [SET]){{< /fatecode >}} -Returns the index of the first occurrence of `[COMPUTATION]` in `[COLLECTION]`, -starting at 0. +Returns the index of the first occurrence of `[COMPUTATION]` in `[LIST]` or +`[SET]`, starting at 0. ### IS MEMBER -{{< fatecode >}}(is_member [COMPUTATION] [COLLECTION]){{< /fatecode >}} +{{< fatecode >}}(list:is_member [COMPUTATION] [LIST]){{< /fatecode >}} +{{< fatecode >}}(set:is_member [COMPUTATION] [SET]){{< /fatecode >}} -Returns true if, and only if, `[COMPUTATION]` is in `[COLLECTION]`. +Returns true if, and only if, `[COMPUTATION]` is in `[LIST]` or `[SET]`. ### SIZE -{{< fatecode >}}(size [COLLECTION]){{< /fatecode >}} +{{< fatecode >}}(list:size [LIST]){{< /fatecode >}} +{{< fatecode >}}(set:size [SET]){{< /fatecode >}} -Returns the size (`[INT]`) of `[COLLECTION]`. +Returns the size (`[INT]`) of `[LIST]` or `[SET]`. ### IS EMPTY -{{< fatecode >}}(is_empty [COLLECTION]){{< /fatecode >}} +{{< fatecode >}}(list:is_empty [LIST]){{< /fatecode >}} +{{< fatecode >}}(set:is_empty [SET]){{< /fatecode >}} + +Returns true if, and only if `[LIST]` or `[SET]` is empty. + +### REMOVE ONE COPY +{{< fatecode >}}(list:remove [COMPUTATION*]+ [LIST]){{< /fatecode >}} +{{< fatecode >}}(set:remove [COMPUTATION*]+ [SET]){{< /fatecode >}} + +Returns a copy of the collection with one instance of `[COMPUTATION*]` having been removed. The variable shorthand cannot be used if the collection is a collection of strings. + +As a shorthand, multiple computations can be specified. They will all be removed +in order. + +### REMOVE ALL COPIES +{{< fatecode >}}(list:remove_each [COMPUTATION*]+ [LIST]){{< /fatecode >}} +{{< fatecode >}}(set:remove_each [COMPUTATION*]+ [SET]){{< /fatecode >}} + +Returns a copy of the collection with all instances of `[COMPUTATION*]` having been removed. The variable shorthand cannot be used if the collection is a collection of strings. + +As a shorthand, multiple computations can be specified. They will all be removed +from the list. + +### REMOVE ALL ALSO IN +{{< fatecode >}}(list:remove_all [removed: COLLECTION]+ [LIST]){{< /fatecode >}} +{{< fatecode >}}(set:remove_all [removed: COLLECTION]+ [SET]){{< /fatecode >}} + +Returns a copy of the collection with all elements of `[removed]` having been +removed. + +As a shorthand, multiple `[removed]` can be specified. Their elements will all +be removed. + +### REMOVE AT +{{< fatecode >}}(list:remove_at [INT] [LIST]){{< /fatecode >}} +{{< fatecode >}}(set:remove_at [INT] [SET]){{< /fatecode >}} + +Returns a copy of the collection with the element at index `[INT]` having been +removed. + +### PUSH ELEMENT +{{< fatecode >}}(list:push_left [COMPUTATION*] [LIST]){{< /fatecode >}} +{{< fatecode >}}(list:push_right [COMPUTATION*] [LIST]){{< /fatecode >}} +{{< fatecode >}}(set:push_left [COMPUTATION*] [SET]){{< /fatecode >}} +{{< fatecode >}}(set:push_right [COMPUTATION*] [SET]){{< /fatecode >}} + +Returns a list corresponding to the given `[LIST]` or `[SET]` to which the +`[COMPUTATION*]` has been added to the right (`push_right`) or the left +(`push_left`). + +### POP ELEMENT +TODO + +### PARTITION +TODO + +### PARTITION (INDEXED) +TODO -Returns true if, and only if `[COLLECTION]` is empty. +### SORT +TODO ### FILTER ELEMENTS -{{< fatecode >}}(filter [LAMBDA BOOL (X)] [X COLLECTION]){{< /fatecode >}} -{{< fatecode >}}(filter [LAMBDA BOOL (X Y0 ... YN)] [X COLLECTION] [Y0 COMPUTATION*] ... [YN COMPUTATION*]){{< /fatecode >}} +{{< fatecode >}}(list:filter [LAMBDA BOOL (X)] [X LIST]){{< /fatecode >}} +{{< fatecode >}}(set:filter [LAMBDA BOOL (X)] [X SET]){{< /fatecode >}} -Returns a copy of `[X COLLECTION]` in which only the elements for which -`[LAMBDA BOOL (X)]` returns `true` remain. If the lambda function needs extra -parameters, use the second syntax, which adds those parameters at the end of the -`(filter ...)` call. Note that the variable shorthand cannot be used for these -extra parameters. +Returns a copy of `[X LIST]` or `[X SET]` in which only the elements for which +`[LAMBDA BOOL (X)]` returns `true` remain. ### FILTER ELEMENTS (INDEXED) -{{< fatecode >}}(indexed_filter [LAMBDA BOOL (INT X)] [X COLLECTION]){{< /fatecode >}} -{{< fatecode >}}(indexed_filter [LAMBDA BOOL (INT X Y0 ... YN)] [X COLLECTION] [Y0 COMPUTATION*] ... [YN COMPUTATION*]){{< /fatecode >}} +{{< fatecode >}}(list:indexed_filter [LAMBDA BOOL (INT X)] [X LIST]){{< /fatecode >}} +{{< fatecode >}}(set:indexed_filter [LAMBDA BOOL (INT X)] [X SET]){{< /fatecode >}} -Returns a copy of `[INT X COLLECTION]` in which only the elements for which +Returns a copy of `[X LIST]` or `[X SET]` in which only the elements for which `[LAMBDA BOOL (INT X)]` (with `INT` being the element's index) returns `true` -remain. If the lambda function needs extra parameters, use the second syntax, -which adds those parameters at the end of the `(indexed_filter ...)` call. Note -that the variable shorthand cannot be used for these extra parameters. +remain. ### FOLD OVER COLLECTION -{{< fatecode >}}(foldl [LAMBDA X (X Y)] [X COMPUTATION*] [Y COLLECTION]){{< /fatecode >}} -{{< fatecode >}}(foldl [LAMBDA X (X Y Z0 ... ZN)] [X COMPUTATION*] [Y COLLECTION] [Z0 COMPUTATION*] ... [ZN COMPUTATION*]){{< /fatecode >}} -{{< fatecode >}}(foldr [LAMBDA X (X Y)] [X COMPUTATION*] [Y COLLECTION]){{< /fatecode >}} -{{< fatecode >}}(foldr [LAMBDA X (X Y Z0 ... ZN)] [X COMPUTATION*] [Y COLLECTION] [Z0 COMPUTATION*] ... [ZN COMPUTATION*]){{< /fatecode >}} +{{< fatecode >}}(list:foldl [LAMBDA X (X Y)] [X COMPUTATION*] [Y LIST]){{< /fatecode >}} +{{< fatecode >}}(list:foldr [LAMBDA X (X Y)] [X COMPUTATION*] [Y LIST]){{< /fatecode >}} +{{< fatecode >}}(set:foldl [LAMBDA X (X Y)] [X COMPUTATION*] [Y SET]){{< /fatecode >}} +{{< fatecode >}}(set:foldr [LAMBDA X (X Y)] [X COMPUTATION*] [Y SET]){{< /fatecode >}} Returns the result of iterating `[LAMBDA X (X Y)]` over `[Y COLLECTION]`, with `[X COMPUTATION*]` being the initial value. The direction of the iteration is by ascending index order when using `foldl`, and the opposite order when using -`foldr`. Extra parameters for the lambda function can be passed as extra -parameters of the call. Note that the variable shorthand cannot be used for -those extra parameters, nor for the initial value. +`foldr`. The variable shorthand cannot be used for the initial value if the +lambda function returns a string. ### MERGE COLLECTIONS -{{< fatecode >}}(merge_to_list [LAMBDA O (X Y)] [X COLLECTION] [Y COLLECTION]){{< /fatecode >}} -{{< fatecode >}}(merge_to_list [LAMBDA O (X Y Z0 ... ZN)] [X COLLECTION] [Y COLLECTION] [Z0 COMPUTATION*] ... [ZN COMPUTATION*]){{< /fatecode >}} -{{< fatecode >}}(merge_to_set [LAMBDA O (X Y)] [X COLLECTION] [Y COLLECTION]){{< /fatecode >}} -{{< fatecode >}}(merge_to_set [LAMBDA O (X Y Z0 ... ZN)] [X COLLECTION] [Y COLLECTION] [Z0 COMPUTATION*] ... [ZN COMPUTATION*]){{< /fatecode >}} -Merges two collections into either a list or a set. This version of merging -only continues as long as both collections have elements. Thus, extra elements -in either list are ignored. Extra parameters for the lambda function can be -passed as extra parameters of the call. Note that the variable shorthand cannot -be used for those extra parameters. +{{< fatecode >}}(list:merge [LAMBDA O (X Y)] [X LIST|X SET] [Y LIST|Y SET]){{< /fatecode >}} +{{< fatecode >}}(set:merge [LAMBDA O (X Y)] [X LIST|X SET] [Y LIST|Y SET]){{< /fatecode >}} +Merges two collections into either a list (`list:merge`) or a set +(`set:merge`). This version of merging only continues as long as both +collections have elements. Thus, extra elements in either list are ignored. ### SAFE-MERGE COLLECTIONS -{{< fatecode >}}(safe_merge_to_list [LAMBDA O (X Y)] [X COMPUTATION*] [X COLLECTION] [Y COMPUTATION*] [Y COLLECTION]){{< /fatecode >}} -{{< fatecode >}}(safe_merge_to_list [LAMBDA O (X Y Z0 ... ZN)] [X COMPUTATION*] [X COLLECTION] [Y COMPUTATION*] [Y COLLECTION] [Z0 COMPUTATION*] ... [ZN COMPUTATION*]){{< /fatecode >}} -{{< fatecode >}}(safe_merge_to_set [LAMBDA O (X Y)] [X COLLECTION] [X COMPUTATION*] [Y COLLECTION] [Y COMPUTATION*]){{< /fatecode >}} -{{< fatecode >}}(safe_merge_to_set [LAMBDA O (X Y Z0 ... ZN)] [X COLLECTION] [X COMPUTATION*] [Y COLLECTION] [Y COMPUTATION*] [Z0 COMPUTATION*] ... [ZN COMPUTATION*]){{< /fatecode >}} -Merges two collections into either a list or a set. This version of merging -continues as long as either collection has elements. Hence the extra two -parameters compared to the non-safe version: these correspond to the value used -for the lambda when a collection has ran out of elements but the other has not. -Extra parameters for the lambda function can be passed as extra parameters of -the call. Note that the variable shorthand cannot be used for those extra -parameters. +{{< fatecode >}}(list:safe_merge [LAMBDA O (X Y)] [X LIST|X SET] [X COMPUTATION] [Y LIST|Y SET] [Y COMPUTATION]){{< /fatecode >}} +{{< fatecode >}}(set:safe_merge [LAMBDA O (X Y)] [X LIST|X SET] [X COMPUTATION] [Y LIST|Y SET] [Y COMPUTATION]){{< /fatecode >}} +Safely merges two collections into either a list (`list:safe_merge`) or a set +(`set:safe_merge`). This version of merging continues as long as either +collection has elements. If one of the two collections runs out of elements +before the other, it uses the provided default value (`[X COMPUTATION]` for the +first list, `[Y COMPUTATION]` for the second one). ### MERGE COLLECTIONS (INDEXED) -{{< fatecode >}}(indexed_merge_to_list [LAMBDA O (INT X Y)] [X COLLECTION] [Y COLLECTION]){{< /fatecode >}} -{{< fatecode >}}(indexed_merge_to_list [LAMBDA O (INT X Y Z0 ... ZN)] [X COLLECTION] [Y COLLECTION] [Z0 COMPUTATION*] ... [ZN COMPUTATION*]){{< /fatecode >}} -{{< fatecode >}}(indexed_merge_to_set [LAMBDA O (INT X Y)] [X COLLECTION] [Y COLLECTION]){{< /fatecode >}} -{{< fatecode >}}(indexed_merge_to_set [LAMBDA O (INT X Y Z0 ... ZN)] [X COLLECTION] [Y COLLECTION] [Z0 COMPUTATION*] ... [ZN COMPUTATION*]){{< /fatecode >}} -Merges two collections into either a list or a set, indicating the index of both -elements as first parameter for the lambda function. This version of merging -only continues as long as both collections have elements. Thus, extra elements -in either list are ignored and there is only one index passed as parameter for -the lambda function. Extra parameters for the lambda function can be -passed as extra parameters of the call. Note that the variable shorthand cannot -be used for those extra parameters. +{{< fatecode >}}(list:indexed_merge [LAMBDA O (INT X Y)] [X LIST|X SET] [Y LIST|Y SET]){{< /fatecode >}} +{{< fatecode >}}(set:indexed_merge [LAMBDA O (INT X Y)] [X LIST|X SET] [Y LIST|Y SET]){{< /fatecode >}} +Merges two collections into either a list (`list:merge`) or a set +(`set:merge`). This version of merging only continues as long as both +collections have elements. Thus, extra elements in either list are ignored. +The first parameter passed to the lambda function is the index of the element +in both collections. ### SAFE-MERGE COLLECTIONS (INDEXED) -{{< fatecode >}}(safe_indexed_merge_to_list [LAMBDA O (INT X INT Y)] [X COMPUTATION*] [X COLLECTION] [Y COMPUTATION*] [Y COLLECTION]){{< /fatecode >}} -{{< fatecode >}}(safe_indexed_merge_to_list [LAMBDA O (INT X INT Y Z0 ... ZN)] [X COMPUTATION*] [X COLLECTION] [Y COMPUTATION*] [Y COLLECTION] [Z0 COMPUTATION*] ... [ZN COMPUTATION*]){{< /fatecode >}} -{{< fatecode >}}(safe_indexed_merge_to_set [LAMBDA O (INT X INT Y)] [X COMPUTATION*] [X COLLECTION] [Y COMPUTATION*] [Y COLLECTION]){{< /fatecode >}} -{{< fatecode >}}(safe_indexed_merge_to_set [LAMBDA O (INT X INT Y Z0 ... ZN)] [X COMPUTATION*] [X COLLECTION] [Y COMPUTATION*] [Y COLLECTION] [Z0 COMPUTATION*] ... [ZN COMPUTATION*]){{< /fatecode >}} -Merges two collections into either a list or a set. This version of merging -continues as long as either collection has elements. Hence the extra two -parameters compared to the non-safe version: these correspond to the value used -for the lambda when a collection has ran out of elements but the other has not. -This is also the reason why two indices are given. The index given for a list -that has ran out of elements is equal the size of the list. -Extra parameters for the lambda function can be passed as extra parameters of -the call. Note that the variable shorthand cannot be used for those extra -parameters. +{{< fatecode >}}(list:indexed_safe_merge [LAMBDA O (INT X INT Y)] [X LIST|X SET] [X COMPUTATION] [Y LIST|Y SET] [Y COMPUTATION]){{< /fatecode >}} +{{< fatecode >}}(set:indexed_safe_merge [LAMBDA O (INT X INT Y)] [X LIST|X SET] [X COMPUTATION] [Y LIST|Y SET] [Y COMPUTATION]){{< /fatecode >}} +Safely merges two collections into either a list (`list:safe_merge`) or a set +(`set:safe_merge`). This version of merging continues as long as either +collection has elements. If one of the two collections runs out of elements +before the other, it uses the provided default value (`[X COMPUTATION]` for the +first list, `[Y COMPUTATION]` for the second one). The first and third parameters +passed to the lambda function correspond to the index of the element in either +collection. It does not increase if the collection has no more elements and is +using the default value. |


