Wikifunctions:Catalogue/List operations
Appearance
- Typed list (Z881): A list containing items of the same type
Basic list/iterable functions
- length of a list (Z12681): number of objects on a list
- List equality (Z889): lists are exactly the same elements in the same order (whether or not the list is explicitly typed)
- same list (Z18646): returns True if all the elements in two lists are equal and both lists have the same Type
- first element (Z811): returns the first element of the input list (labelled “Item 1”)
- second element (Z16360): returns the second element from a list
- last element (Z12964): the final element of a list
- Is empty list (Z813): returns true if and only if the list has zero elements
- contains (Z12696): check whether a list contains a certain element
- are all true (Z12684): returns true if every list item is true
- all meet criteria (Z12735): every item on the list, when evaluated by the criteria function, evaluates to true
- is any true (Z12698): checks whether in a list of Boolean any is true
- any meet criteria (Z12738): return true if one the items of a list meets criteria given by a function, otherwise false
- is single element list (Z12755): returns true if the list has exactly one element
- is two element list (Z12759): returns true if and only if the list has exactly two elements
- is longer list (Z12851): true if first list is longer than the second, false when equal or shorter
- lists have equal length (Z12864): true if the lists have an equal number of elements, false otherwise
- lists have unequal length (Z13310): Returns true if lists have different length
- index of first listing (1...N) (Z13708): returns the position on a list of the element tested (1...N)
- get the nth element of a list (Z13397): When given a valid index (1-based) return the object at that position in the list
Complex list/iterable functions
- is permutation (Z12741): tests if one list is a permutation of another
- is superset (Z12846): test whether the first list contains all elements of the second (and contains at least as many as any repeated elements)
- is there a common element on these lists? (Z13752): returns true if the two lists share at least one common element
- index of element on list with metric value (Z19536): returns the index (1...N) of the first element on the list which when passed to the metric function has a given natural number metric value. Returns 0 if none of the list satisfy.
Functions with list outputs
- If a function specifies an output list with a type other than Object (Z1) (that is, it specifies a "properly typed" list), mismatched elements cause an error if the implementation is in code.
- If all objects in an output list have the same type, the list takes that type instead of being Z1-typed. This only happens if the implementation is in code. For compositions, you can use return Typed list (Z18475) to get the same result.
- If a code implementation needs converted objects (provided by a Type converter to code (Z46)), any list input must be properly typed (objects in a Z1-typed list are not converted). Similarly, any list output must be properly typed (not Object (Z1) in the function specification) or else conversion into a Wikifunctions object will fail.
- If a code implementation does not need converted objects, you can use untype a list (Z17895) to convert a properly typed list to Z1-typed (but this is not officially supported).
- return Typed list (Z18475): returns a Typed list with the correct Type if all elements have the same Type, otherwise untyped (Z1-typed)
- untype a list (Z17895): takes a typed list and returns the same objects in an untyped (Z1-typed) list (returns a Z1-typed list unchanged)
- return Typed or untyped list (Z18729): according to the option chosen, returns an heuristically Typed list or an untyped (Z1-Typed) list
- reverse list preserving list typing/untyping (Z18759): deals with either typed or untyped lists, and preserves the typing
- generate list of length (Z21821): calls the given function for each index 1..n, appending the results into a list
- replicate object n times (Z21389): no description
- element to list (Z14046): makes a single-element list from the given element
- append element to Typed list (Z12961): adds the supplied element to the end of the supplied list
- list without last element (Z12967): returns a list without the last element
- get the first n elements of an untyped list (Z13366): return a list of the first n elements of a supplied list
- remove first N elements of list (Z13369): returns the supplied list without the first N elements (an empty list if the number of items to be removed is greater than the length of the list or the number of items to be removed is invalid)
- remove last n elements of a list (Z13373): returns the supplied list without the last n elements. if the number of items to be remove is higher than length of the list or number of items to be remove is invalid it removes all items from list
- remove the nth element from a list (Z13429): When given a valid index remove the element at the position and return the supplied list otherwise return nothing
- get the last n elements of a list (Z13362): return a list of the last n elements of a supplied list .
- concatenate two untyped lists (Z12767): appends two lists together and preserves the order of elements
- flat a list (Z12676): flatten a list to limited depth
- interleave lists (Z13155): interleave lists of same length together such that [ A .. Z ], [ 1 .. 26 ]...n return [ A, 1, B, 2 .. n] and if there are uneven list of same size or if this list doesnt contain lists throughout it returns an empty list
- split list into a list of two ~equal length lists (Z13224): Keeps the order of elements, first half on first list. If odd length, the first list will have just over half.
- faro out-shuffle (Z13247): a perfect riffle shuffle see https://en.wikipedia.org/wiki/Faro_shuffle
- remove first matching element from list (Z12856): returns a list equal to the original list with the first matching element removed
- remove all matching elements from list (Z13081): returns a list equal to the original list with all matching element removed
- remove duplicates from untyped list (Z13078): remove second and subsequent duplicate items without changing the order of the list
- Sort ascending
- add vectors (containing natural numbers) (Z17670): vectors must have equal length
- average vectors (containing natural numbers) (Z17675): Vectors must be equal length. Uses integer division, so (a[i]+b[i])//2 will round down if (a[i]+b[i]) is odd
In-built functions with list outputs
These operate on object-typed lists, so may not need a different version for each type. However, code implementations cannot currently generate lists of objects (other than string/boolean). So code implementations will not work on these functions.
- Map Function (Z873): return a list of elements processed by a given function
- Filter Function (Z872): return elements meeting criteria given by a function
- Reduce Function (Z876) (actually left-associative fold)
- left fold (Z12781) (actually left-associative reduce)
- reduce (list only) (Z20089) w/ initial empty check
- right fold (Z12753) (actually right-associative reduce)
- left fold (Z12781) (actually left-associative reduce)
- prepend element to list (Z810): adds the supplied element to the start of the supplied list
- list without first element (Z812): returns a list without the first element