Wikifunctions:Catalogue/List operations
Appearance
Properties
- Typed list has the same Object for its Type (Z18636): returns True if a Typed list uses the referenced Persistent object (a Type) in its generic Type specification (a Function call to the Z881/Typed list function)
- length of a list (Z12681): number of objects on a list
- list has length (Z30164): Description missing
- Is empty list (Z813): returns true if and only if the list has zero elements
- list has at most one element (Z32302): i.e. the list has zero or one element
- 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
- lists have equal length (Z12864): true if the lists have an equal number of elements, false otherwise
- size of matrix (Z31612): returns (numRows, numCols)
- dimensions of list of lists (Z31605): returns e.g. [numRows, numCols] for a rectangular matrix; if the tensor is jagged (not uniform length) at any level, that and any deeper levels are ignored
- list has length (Z30164): Description missing
- depth of list of lists up to jaggedness (Z31592): returns 1 for a 1D array (vector) or jagged 2D array, 2 for a rectangular 2D array (matrix), etc.
- contains (Z12696): test whether a list contains a certain element
- any boolean equal to (Z34367): Returns true if at least one element of a list of boolean is equal to the comparison; always returns false for empty lists
- any meet criteria (Z12738): return true if one the items of a list meets criteria given by a function, otherwise false
- all meet criteria (Z12735): every item on the list, when evaluated by the criteria function, evaluates to true
- Is element of a set (Z34378): Tests wether an element is included in a set
- contains all of list (Z12846): test whether the first list contains all elements of the second (and contains at least as many of any repeated elements)
- List equality (Z889): lists are exactly the same elements in the same order (whether or not either list is explicitly typed). See Z18646 for one that requires same type
- same list (Z18646): returns True if all the elements in two lists are equal and both lists have the same Type. See Z889 for one that does not require same type
- set equality (Z34273): Tests whether two sets are equal (have the same elements)
- Levenshtein distance between two lists (Z31013): computes the minimum number of edits (insertions, deletions, and substitutions) on elements that would be needed to transform one list into the other
- Levenshtein distance between lists is at most n? (Z31019): determines if the minimum number of edits (insertions, deletions, and substitutions) on elements that would be needed to transform one list into the other is within a threshold
- Levenshtein distance (Z10393): a metric for measuring the difference between two sequences by calculating the minimum number of single-character edits between 2 strings.
- Hamming distance (Z31026): computes the minimum number of substitutions (or, corruption errors) on elements that would be needed to transform one list into the other
- count occurrences of element on list (Z29413): returns the number of times the tested element has object equality with the elements of the list
- index of first listing (1...N) – note limitation (Z13708): returns the position (1…n) of the first matching element, except where the list is untyped (Z1) and the match-object has custom conversion (its type has a converter to code)
- index of first sub-list (start) (Z28715): returns the 1-based index of the first occurrence of the given sub-list in a list, or zero if not found (by convention, an empty sub-list starts at index 1)
- 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.
- longest common sublist (Z31575): Description missing
- Typed list has as its first item (Z21613): true if the first item in the Typed list is the same object
- Typed list has as its last item (Z31758): Description missing
Indexing/slicing
- first element (Z811): returns the first element of the input list (labelled “Item 1”)
- second element (performance) (Z29446): Returns the second object in a Typed list. Fails for shorter lists. An error-handling version is available elsewhere.
- last element (Z12964): the final element of a list
- get the nth element of a list (Z13397): When given a valid index (1-based) return the object at that position in the list
- advance N elements (Z26904): Returns the element N elements after the initial element in a list (wrapping around once complete).
- get (i,j)th element from list of lists (Z30282): both indices are 1..=N
- take sub-sequence of list (Z26556): clamps indices to valid range (1..=N); returns empty if end < start
- every nth item of list starting with first (Z31809): For example, every 3rd item from a list of 10 would be the 1st, 4th, 7th, and 10th
- list without first element (Z812): returns a list without the first element
- list without last element (Z12967): returns a list without the last element
Removal/filtering
- 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
- keep elements common with other list (Z22865): returns the first list in the same order but without any elements that are not on the second list
- Union of sets (Z34538): Computes the union of two sets, the set of all the elements who are either in the first or the second set
- remove duplicates preserving typing/untyping (Z19205): deals with either typed or untyped lists, and preserves the typing. Following Z18759
- trim element from start of list (Z31874): Description missing
- remove element at index (1..=N) on list (Z31364): Description missing
- 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
- list of lists without nth elements of each (1..=N) (Z35597): Description missing
- 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 remove is higher than length of list or number of items to remove is invalid it removes all items from list
- filter list through list of indices (Z29400): Description missing
- Filter Function (Z872): return elements meeting criteria given by a function
- Filter but fallback if empty (Z33453): Filter a list by a given function, returning the original list if the filtered list is empty
- partition list (Z21809): sort elements into one of two lists based on a predicate function: matches (trues) first, then falses
- filter with second common element (Z28316): filter list using a two-argument function with the second argument fixed for all tests
- filter by Key reference (Z27413): filters a list to include only objects whose value for the given Key reference is the same as the specified object (no nesting)
Substitution/transformation
- list identity (Z15142) (no-op)
- return Typed or untyped list (Z18729): according to the option chosen, returns an heuristically Typed list or an untyped (Z1-Typed) list
- set i-th element on list (1..=N) (Z31369): Description missing
- map function (Z873): return a list of elements processed by a given function
Insertion
- prepend element to list (Z810): adds the supplied element to the start of the supplied list
- append element to untyped list (Z18597): adds the supplied element to the end of the supplied untyped (object-typed) list
- append element to Typed list (Z12961): adds the supplied element to the end of the supplied list
- Append element to set (Z34519): Append an element to a set, equivalent to A ∪ {B}
- *list with added element unless already present (Z24655): expects and returns an object-typed ("untyped") list
- pad end of list (Z33720): Description missing
- insert element into list at index (1..=N+1) (Z31345): Description missing
- concatenate two untyped lists (Z12767): joins two lists together without changing the order of elements (the result may not be an untyped list but both arguments should be, although some list types will work correctly)
Generation
- element to list (Z14046): makes a single-element list from the given element
- wrap in list unless list (Z27685): if the argument is a typed or untyped list, returns that list, else returns a new list containing only the argument
- given object within list within list (Z24291): returns a list containing a list containing the object (which may be a list)
- replicate object n times (Z21389): Description missing
- generate untyped list of length (Z21821): calls the given function for each index 1..=n, appending the results into a list (zero-indexed version at Z24387)
- generate list from function, index 0..=n (Z23921): calls the given function for each index 0..=n, appending the results into a list. Reversed inputs of Z24387.
- natural number range (Z13831): Get a list of natural numbers spanning a given range
- generate range of Integers (Z31619): if last < first, returns empty list
- table from function of row and column elements (Z29286): creates a 2d matrix as a list of lists with elements f(ri,cj) where ri is the ith element of the row element list, and cj is the jth element of the column element list
- powerset (Z18194): Description missing
Ordering and grouping
- reverse list preserving list typing/untyping (Z18759): deals with either typed or untyped lists, and preserves the typing
- reverse untyped list (Z12668): reverse the order of elements in an untyped ordered list
- reverse Typed list (Z18479): returns a Typed list with the order of the elements reversed
- reverse list (of natural numbers) (Z17770)
- reverse list (of integers) (Z17774)
- reverse list (of days of the week) (Z17778)
- transpose rational matrix (Z24176): Description missing
- circular shift list n places left (Z31355): removes the first n elements and appends them to the remainder; negative n shifts right instead (move last n to start)
- sort according to other list (Z29725): Description missing
- sort list by increasing metric function (Z19510): The metric function should take each object in the list and return a natural number.
- (#) order list with comparing function (Z27612): Description missing
- sort list ascending (natural numbers) (Z17873): Description missing
- sort list ascending (integers) (Z17869): reorders a list of integers so it is in ascending order
- sort a list by string length (Z12671): Description missing
- sort in alphabetic order (Z18281): sorts a list of strings into alphabetic order
- filter list through list of indices (Z29400): Description missing
- faro out-shuffle (Z13247): a perfect riffle shuffle see https://en.wikipedia.org/wiki/Faro_shuffle
- group by selector func and apply func w/ key, vals (Z30157): Description missing
- run-length encoding (Z34790): Description missing
- chunk list into lists of length <= N (Z29795): if N doesn't evenly divide the input list's length, the last of the output lists will be shorter
- 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.
- 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)
- flatten untyped list (Z12676): flatten an (untyped) list to limited depth
- flatten Typed list (Z23606): flatten a Typed list to limited depth
- concatenate many untyped lists (Z27665): Description missing
- 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
Matrix math
Since we don't have specific types for vectors or matrices, vectors are represented as a list and matrices as a list of lists (to be interpreted as a list of rows).
- size of matrix (Z31612): returns (numRows, numCols)
- is matrix idempotent (Z31747): returns Boolean depending on the idempotence of the matrix
- determinant of square matrix (Rational numbers) (Z35585): Description missing
- same list of rationals (Z24166): True if the lists of rationals are exactly equal when each is in its simplified form.
- get the nth element of a list (Z13397): When given a valid index (1-based) return the object at that position in the list
- remove element at index (1..=N) on list (Z31364): Description missing
- transform elements of list of lists (Z32806): Description missing
- add rational to all elements of a list (Z31818): returns the array with the rational number added to all values of the array
- add vectors (rational) (Z24055): Description missing
- rational times vector (Z24060): Description missing
- dot product (rational vectors) (Z24185): returns the dot or scalar product of two rational vectors
- get cross product (Z21903): Finds the cross product of two integer vectors
- matrix multiplication (Z24239): returns the product of two matrices
- norm of a vector (Z24346): Description missing
- element to list (Z14046): makes a single-element list from the given element
- list to singleton-list (Z29301): returns a list within which each element of the given list is returned as a list containing only that element
- right product of matrix with vector (Z24191): Description missing
- left multiplication between vector and matrix (Z24236): Description missing
- outer product, u⊗v (rational vectors) (Z29308): creates a 2d matrix as a list of lists with elements are all products of an element in the first vector with an element in the second vector
- prepend element to list (Z810): adds the supplied element to the start of the supplied list
- append element to untyped list (Z18597): adds the supplied element to the end of the supplied untyped (object-typed) list
- reverse list preserving list typing/untyping (Z18759): deals with either typed or untyped lists, and preserves the typing
- transpose rational matrix (Z24176): Description missing
- given object within list within list (Z24291): returns a list containing a list containing the object (which may be a list) (useful for creating 1x1 matrixes)
- identity matrix (Z24290): Returns the identity matrix, given the dimension
- table from function of row and column elements (Z29286): creates a 2d matrix as a list of lists with elements f(ri,cj) where ri is the ith element of the row element list, and cj is the jth element of the column element list
Functions expecting a list argument
Functions with list outputs
- If a function specifies an output list with a type other than 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 custom-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 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 list if custom converters (Z28691) to convert a properly typed list to Z1-typed (but this is not officially supported). (The list will remain properly typed if there are no custom converters to code. Use untype a list (Z17895) to make the list Z1-typed unconditionally.)