(219 lines)
1 '\" t2 .\" Copyright (c) 2026 Bruce Hill3 .\" All rights reserved.4 .\"5 .TH List 3 2026-03-11 "Tomo man-pages"6 .SH NAME7 List \- a Tomo type8 .SH LIBRARY9 Tomo Standard Library10 .fi11 .SH METHODS13 .TP14 .BI List.binary_search\ :\ func(list:\ [T],\ by:\ func(x,y:&T->Int32)\ =\ T.compare\ ->\ Int)15 Performs a binary search on a sorted list.17 For more, see:18 .BR Tomo-List.binary_search (3)21 .TP22 .BI List.by\ :\ func(list:\ [T],\ step:\ Int\ ->\ [T])23 Creates a new list with elements spaced by the specified step value.25 For more, see:26 .BR Tomo-List.by (3)29 .TP30 .BI List.clear\ :\ func(list:\ @[T]\ ->\ Void)31 Clears all elements from the list.33 For more, see:34 .BR Tomo-List.clear (3)37 .TP38 .BI List.counts\ :\ func(list:\ [T]\ ->\ {T=Int})39 Counts the occurrences of each element in the list.41 For more, see:42 .BR Tomo-List.counts (3)45 .TP46 .BI List.find\ :\ func(list:\ [T],\ target:\ T\ ->\ Int?)47 Finds the index of the first occurrence of an element (if any).49 For more, see:50 .BR Tomo-List.find (3)53 .TP54 .BI List.from\ :\ func(list:\ [T],\ first:\ Int\ ->\ [T])55 Returns a slice of the list starting from a specified index.57 For more, see:58 .BR Tomo-List.from (3)61 .TP62 .BI List.has\ :\ func(list:\ [T],\ target:\ T\ ->\ Bool)63 Checks if the list has an element.65 For more, see:66 .BR Tomo-List.has (3)69 .TP70 .BI List.heap_pop\ :\ func(list:\ @[T],\ by:\ func(x,y:&T->Int32)\ =\ T.compare\ ->\ T?)71 Removes and returns the top element of a heap or \fBnone\fR if the list is empty. By default, this is the *minimum* value in the heap.73 For more, see:74 .BR Tomo-List.heap_pop (3)77 .TP78 .BI List.heap_push\ :\ func(list:\ @[T],\ item:\ T,\ by\ =\ T.compare\ ->\ Void)79 Adds an element to the heap and maintains the heap property. By default, this is a *minimum* heap.81 For more, see:82 .BR Tomo-List.heap_push (3)85 .TP86 .BI List.heapify\ :\ func(list:\ @[T],\ by:\ func(x,y:&T->Int32)\ =\ T.compare\ ->\ Void)87 Converts a list into a heap.89 For more, see:90 .BR Tomo-List.heapify (3)93 .TP94 .BI List.insert\ :\ func(list:\ @[T],\ item:\ T,\ at:\ Int\ =\ 0\ ->\ Void)95 Inserts an element at a specified position in the list.97 For more, see:98 .BR Tomo-List.insert (3)101 .TP102 .BI List.insert_all\ :\ func(list:\ @[T],\ items:\ [T],\ at:\ Int\ =\ 0\ ->\ Void)103 Inserts a list of items at a specified position in the list.105 For more, see:106 .BR Tomo-List.insert_all (3)109 .TP110 .BI List.pop\ :\ func(list:\ &[T],\ index:\ Int\ =\ -1\ ->\ T?)111 Removes and returns an item from the list. If the given index is present in the list, the item at that index will be removed and the list will become one element shorter.113 For more, see:114 .BR Tomo-List.pop (3)117 .TP118 .BI List.random\ :\ func(list:\ [T],\ random:\ func(min,max:Int64->Int64)?\ =\ none\ ->\ T?)119 Selects a random element from the list.121 For more, see:122 .BR Tomo-List.random (3)125 .TP126 .BI List.remove_at\ :\ func(list:\ @[T],\ at:\ Int\ =\ -1,\ count:\ Int\ =\ 1\ ->\ Void)127 Removes elements from the list starting at a specified index.129 For more, see:130 .BR Tomo-List.remove_at (3)133 .TP134 .BI List.remove_item\ :\ func(list:\ @[T],\ item:\ T,\ max_count:\ Int\ =\ -1\ ->\ Void)135 Removes all occurrences of a specified item from the list.137 For more, see:138 .BR Tomo-List.remove_item (3)141 .TP142 .BI List.reversed\ :\ func(list:\ [T]\ ->\ [T])143 Returns a reversed slice of the list.145 For more, see:146 .BR Tomo-List.reversed (3)149 .TP150 .BI List.sample\ :\ func(list:\ [T],\ count:\ Int,\ weights:\ [Num]?\ =\ none,\ random:\ func(->Num)?\ =\ none\ ->\ [T])151 Selects a sample of elements from the list, optionally with weighted probabilities.153 For more, see:154 .BR Tomo-List.sample (3)157 .TP158 .BI List.shuffle\ :\ func(list:\ @[T],\ random:\ func(min,max:Int64->Int64)?\ =\ none\ ->\ Void)159 Shuffles the elements of the list in place.161 For more, see:162 .BR Tomo-List.shuffle (3)165 .TP166 .BI List.shuffled\ :\ func(list:\ [T],\ random:\ func(min,max:Int64->Int64)?\ =\ none\ ->\ [T])167 Creates a new list with elements shuffled.169 For more, see:170 .BR Tomo-List.shuffled (3)173 .TP174 .BI List.slice\ :\ func(list:\ [T],\ from:\ Int,\ to:\ Int\ ->\ [T])175 Returns a slice of the list spanning the given indices (inclusive).177 For more, see:178 .BR Tomo-List.slice (3)181 .TP182 .BI List.sort\ :\ func(list:\ @[T],\ by\ =\ T.compare\ ->\ Void)183 Sorts the elements of the list in place in ascending order (small to large).185 For more, see:186 .BR Tomo-List.sort (3)189 .TP190 .BI List.sorted\ :\ func(list:\ [T],\ by\ =\ T.compare\ ->\ [T])191 Creates a new list with elements sorted.193 For more, see:194 .BR Tomo-List.sorted (3)197 .TP198 .BI List.to\ :\ func(list:\ [T],\ last:\ Int\ ->\ [T])199 Returns a slice of the list from the start of the original list up to a specified index (inclusive).201 For more, see:202 .BR Tomo-List.to (3)205 .TP206 .BI List.unique\ :\ func(list:\ [T]\ ->\ {T})207 Returns a set of the unique elements of the list.209 For more, see:210 .BR Tomo-List.unique (3)213 .TP214 .BI List.where\ :\ func(list:\ [T],\ predicate:\ func(item:&T\ ->\ Bool)\ ->\ Int)215 Find the index of the first item that matches a predicate function (if any).217 For more, see:218 .BR Tomo-List.where (3)