Handy functions for list manipulation.
Function or value | Description | ||
Full Usage:
allpairs f l1 l2
Parameters:
'a -> 'b -> 'c
-
The function to apply to the pairs.
l1 : 'a list
-
The list of first elements of the pairs.
l2 : 'b list
-
The list of second elements of the pairs.
Returns: 'c list
The list of results of applying f to all the pairs formed
from l1 and l2 .
|
Example
Evaluates to [2; 3; 3; 4; 4; 5] .
|
||
Full Usage:
assoc a l
Parameters:
'a
-
The value to search.
l : ('a * 'b) list
-
The input list.
Returns: 'b
The second component of the pair, if a matching for the first is
found.
|
Example
Evaluates to 3 .
Example
Evaluates to 3 .
Example
Throws System.Exception: find .
|
||
Full Usage:
butlast l
Parameters:
'a list
-
The input list.
Returns: 'a list
All the elements of the input list but the last one.
|
Example
Evaluates to [1;2;3;4] .
Example
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int type 'T list = List<'T>
Throws System.Exception: butlast .
|
||
Full Usage:
chop_list n l
Parameters:
int
-
The index at which the list is chopped.
l : 'a list
-
The input list.
Returns: 'a list * 'a list
The two chopped lists.
|
NoteIt should be replaced with the standard ListModule.SplitAt. Example
Evaluates to ([1;2;3], [4;5;6]) .
Example
Throws System.Exception: chop_list .
Example
Throws System.Exception: chop_list .
|
||
Full Usage:
distinctpairs l
Parameters:
'a list
-
The input list.
Returns: ('a * 'a) list
All pairs of distinct elements from the input list l .
|
|||
Full Usage:
earlier l x y
Parameters:
'a list
-
The input list.
x : 'a
-
The element to search.
y : 'a
-
The element to compare with x .
Returns: bool
true, if x comes earlier than y in l ,
or x is in l but not y . Otherwise, false.
|
Example
Evaluates to true .
Example
Evaluates to true .
Example
Evaluates to false .
Example
Evaluates to false .
Example
Evaluates to false .
|
||
Full Usage:
index x xs
Parameters:
'a
-
The element to search.
xs : 'a list
-
The input list.
Returns: int
The index of the first element that equals x .
Modifiers: inline Type parameters: 'a |
Example
Evaluates to 4 .
Example
Throws System.Collections.Generic.KeyNotFoundException: An index satisfying the predicate was not found in the collection. .
|
||
Full Usage:
insertat i x l
Parameters:
int
-
The index where the item should be inserted.
x : 'a
-
The value to insert.
l : 'a list
-
The input list.
Returns: 'a list
The result list.
|
NoteIt should be replaced with the standard ListModule.InsertAt. Example
Evaluates to [0; 9; 1; 2] .
Example
Throws System.Exception: insertat: list too short for position to
exist .
Example
Throws System.Exception: insertat: list too short for position to
exist .
|
||
Full Usage:
last l
Parameters:
'a list
-
The input list.
Returns: 'a
The last element of the list.
|
NoteIt should be replaced with the standard ListModule.Last. Example
Evaluates to 5 .
Example
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int type 'T list = List<'T>
Throws System.Exception: last .
|
||
Full Usage:
rev_assoc b l
Parameters:
'b
-
The value to search.
l : ('a * 'b) list
-
The input list.
Returns: 'a
The first component of the pair, if a matching for the second is
found.
|
Example
Evaluates to 1 .
Example
Evaluates to 1 .
Example
Throws System.Exception: find .
|