List Module
Contains operations for working with values of type list.
Functions and values
Function or value | Description | ||||
|
Example
val people: string list
val numbers: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val allPairs: list1: 'T1 list -> list2: 'T2 list -> ('T1 * 'T2) list
Evaluates to
|
||||
|
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val append: list1: 'T list -> list2: 'T list -> 'T list
Evaluates to
|
||||
Full Usage:
List.average list
Parameters:
^T list
-
The input list.
Returns: ^T
The resulting average.
Modifiers: inline Type parameters: ^T |
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val average: list: 'T list -> 'T (requires member (+) and member DivideByInt and member Zero)
Evaluates to
|
||||
Full Usage:
List.averageBy projection list
Parameters:
'T -> ^U
-
The function to transform the list elements into the values to be averaged.
list : 'T list
-
The input list.
Returns: ^U
The resulting average.
Modifiers: inline Type parameters: 'T, ^U |
ExampleCalculate average age of persons by extracting their age from a record type.
type People =
{
Name: string
Age: int
}
Multiple items
val string: value: 'T -> string -------------------- type string = System.String Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val getAgeAsFloat: person: People -> float
val person: People
Multiple items
val float: value: 'T -> float (requires member op_Explicit) -------------------- type float = System.Double -------------------- type float<'Measure> = float People.Age: int
val people: People list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val averageBy: projection: ('T -> 'U) -> list: 'T list -> 'U (requires member (+) and member DivideByInt and member Zero)
Evaluates to
|
||||
|
Example
Using the identity function
val input1: int option list
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val choose: chooser: ('T -> 'U option) -> list: 'T list -> 'U list
val id: x: 'T -> 'T
Evaluates to
Example
type Happiness =
| AlwaysHappy
| MostOfTheTimeGrumpy
type People =
{
Name: string
Happiness: Happiness
}
Multiple items
val string: value: 'T -> string -------------------- type string = System.String val takeJustHappyPersons: person: People -> string option
val person: People
People.Happiness: Happiness
union case Happiness.AlwaysHappy: Happiness
union case Option.Some: Value: 'T -> Option<'T>
People.Name: string
union case Happiness.MostOfTheTimeGrumpy: Happiness
union case Option.None: Option<'T>
val candidatesForTheTrip: People list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val choose: chooser: ('T -> 'U option) -> list: 'T list -> 'U list
Evaluates to
Example
val input3: int option list
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int type 'T option = Option<'T>
type 'T list = List<'T>
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val choose: chooser: ('T -> 'U option) -> list: 'T list -> 'U list
val id: x: 'T -> 'T
Example
val input4: string option list
Multiple items
val string: value: 'T -> string -------------------- type string = System.String type 'T option = Option<'T>
type 'T list = List<'T>
union case Option.None: Option<'T>
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val choose: chooser: ('T -> 'U option) -> list: 'T list -> 'U list
val id: x: 'T -> 'T
Example
Using the identity function
val input5: int option list
union case Option.Some: Value: 'T -> Option<'T>
union case Option.None: Option<'T>
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val choose: chooser: ('T -> 'U option) -> list: 'T list -> 'U list
val id: x: 'T -> 'T
|
||||
|
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val chunkBySize: chunkSize: int -> list: 'T list -> 'T list list
Evaluates to
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val chunkBySize: chunkSize: int -> list: 'T list -> 'T list list
Evaluates to
|
||||
|
ExampleFor each positive number in the array we are generating all the previous positive numbers
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val collect: mapping: ('T -> 'U list) -> list: 'T list -> 'U list
val x: int
The sample evaluates to [1; 1; 2; 1; 2; 3; 1; 2; 3; 4] (added extra spaces for easy reading)
|
||||
Full Usage:
List.compareWith comparer list1 list2
Parameters:
'T -> 'T -> int
-
A function that takes an element from each list and returns an int.
If it evaluates to a non-zero value iteration is stopped and that value is returned.
list1 : 'T list
-
The first input list.
list2 : 'T list
-
The second input list.
Returns: int
Returns the first non-zero result from the comparison function. If the first list has a
larger element, the return value is always positive. If the second list has a larger
element, the return value is always negative. When the elements are equal in the two
lists, 1 is returned if the first list is longer, 0 is returned if they are equal in
length, and -1 is returned when the second list is longer.
Modifiers: inline Type parameters: 'T |
Example
val closerToNextDozen: a: int -> b: int -> int
val a: int
val b: int
val input1: int list
val input2: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val compareWith: comparer: ('T -> 'T -> int) -> list1: 'T list -> list2: 'T list -> int
Evaluates to 0
Example
val closerToNextDozen: a: int -> b: int -> int
val a: int
val b: int
val input1: int list
val input2: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val compareWith: comparer: ('T -> 'T -> int) -> list1: 'T list -> list2: 'T list -> int
Evaluates to -1
Example
val closerToNextDozen: a: int -> b: int -> int
val a: int
val b: int
val input1: int list
val input2: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val compareWith: comparer: ('T -> 'T -> int) -> list1: 'T list -> list2: 'T list -> int
Evaluates to 1
Example
val closerToNextDozen: a: int -> b: int -> int
val a: int
val b: int
val input1: int list
val input2: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val compareWith: comparer: ('T -> 'T -> int) -> list1: 'T list -> list2: 'T list -> int
Evaluates to 1
Example
val closerToNextDozen: a: int -> b: int -> int
val a: int
val b: int
val input1: int list
val input2: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val compareWith: comparer: ('T -> 'T -> int) -> list1: 'T list -> list2: 'T list -> int
Evaluates to -1
|
||||
|
Example
val input: int list list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val concat: lists: 'T list seq -> 'T list
|
||||
|
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val contains: value: 'T -> source: 'T list -> bool (requires equality)
Evaluates to false .
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val contains: value: 'T -> source: 'T list -> bool (requires equality)
Evaluates to true .
Example
val input: (int * string) list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val contains: value: 'T -> source: 'T list -> bool (requires equality)
Evaluates to true .
Example
val input: (int * string) list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val contains: value: 'T -> source: 'T list -> bool (requires equality)
Evaluates to false .
|
||||
|
ExampleCounting the number of occurrences of chars
val input: char list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val countBy: projection: ('T -> 'Key) -> list: 'T list -> ('Key * int) list (requires equality)
val id: x: 'T -> 'T
Evaluates [('H', 1); ('a', 1); ('p', 2); ('y', 1)]
|
||||
|
Example
val input: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val distinct: list: 'T list -> 'T list (requires equality)
Evaluates to [6; 1; 2; 3; 4; 5] .
|
||||
|
Example
val isEven: x: int -> bool
val x: int
val input: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val distinctBy: projection: ('T -> 'Key) -> list: 'T list -> 'T list (requires equality)
|
||||
|
|
||||
Full Usage:
List.exactlyOne list
Parameters:
'T list
-
The input list.
Returns: 'T
The only element of the list.
|
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val exactlyOne: list: 'T list -> 'T
Example
val input: string list
Multiple items
val string: value: 'T -> string -------------------- type string = System.String type 'T list = List<'T>
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val exactlyOne: list: 'T list -> 'T
Will throw the exception: System.ArgumentException: The input sequence was empty
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val exactlyOne: list: 'T list -> 'T
Will throw the exception: System.ArgumentException: The input sequence contains more than one element
|
||||
Full Usage:
List.except itemsToExclude list
Parameters:
'T seq
-
A sequence whose elements that also occur in the input list will cause those elements to be
removed from the result.
list : 'T list
-
A list whose elements that are not also in itemsToExclude will be returned.
Returns: 'T list
A list that contains the distinct elements of list that do not appear in itemsToExclude .
|
Example
val input: (int * string) list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val except: itemsToExclude: 'T seq -> list: 'T list -> 'T list (requires equality)
Evaluates to [(1, "Kirk"); (2, "Spock")] .
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val except: itemsToExclude: 'T seq -> list: 'T list -> 'T list (requires equality)
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val except: itemsToExclude: 'T seq -> list: 'T list -> 'T list (requires equality)
|
||||
|
The predicate is applied to the elements of the input list. If any application returns true then the overall result is true and no further elements are tested. Otherwise, false is returned.
Example
val input: (int * string) list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val exists: predicate: ('T -> bool) -> list: 'T list -> bool
val x: int * string
val n: int
val name: string
|
||||
|
The predicate is applied to matching elements in the two collections up to the lesser of the two lengths of the collections. If any application returns true then the overall result is true and no further elements are tested. Otherwise, if one collections is longer than the other then the ArgumentException exception is raised. Otherwise, false is returned.
ExampleCheck if the sum of pairs (from 2 different lists) have at least one even number
val anEvenSum: a: int -> b: int -> bool
val a: int
val b: int
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val exists2: predicate: ('T1 -> 'T2 -> bool) -> list1: 'T1 list -> list2: 'T2 list -> bool
|
||||
|
Example
val input: (int * string) list
val isEven: x: int -> bool
val x: int
val isComingFromStarTrek: x: int * 'a -> bool
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val filter: predicate: ('T -> bool) -> list: 'T list -> 'T list
Evaluates to [(2, "Kirk"); (4, "Spock")]
|
||||
|
Example
val isEven: x: int -> bool
val x: int
val isGreaterThan: x: 'a -> y: 'a -> bool (requires comparison)
val x: 'a (requires comparison)
val y: 'a (requires comparison)
val input: (int * string) list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val find: predicate: ('T -> bool) -> list: 'T list -> 'T
|
||||
|
Example
val isEven: x: int -> bool
val x: int
val isGreaterThan: x: 'a -> y: 'a -> bool (requires comparison)
val x: 'a (requires comparison)
val y: 'a (requires comparison)
val input: (int * string) list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val findBack: predicate: ('T -> bool) -> list: 'T list -> 'T
|
||||
|
Example
val isEven: x: int -> bool
val x: int
val isGreaterThan: x: 'a -> y: 'a -> bool (requires comparison)
val x: 'a (requires comparison)
val y: 'a (requires comparison)
val input: (int * string) list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val findIndex: predicate: ('T -> bool) -> list: 'T list -> int
|
||||
|
Example
val isEven: x: int -> bool
val x: int
val isGreaterThan: x: 'a -> y: 'a -> bool (requires comparison)
val x: 'a (requires comparison)
val y: 'a (requires comparison)
val input: (int * string) list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val findIndexBack: predicate: ('T -> bool) -> list: 'T list -> int
|
||||
Full Usage:
List.fold folder state list
Parameters:
'State -> 'T -> 'State
-
The function to update the state given the input elements.
state : 'State
-
The initial state.
list : 'T list
-
The input list.
Returns: 'State
The final state value.
|
Applies a function to each element of the collection, threading an accumulator argument
through the computation. Take the second argument, and apply the function to it
and the first element of the list. Then feed this result into the function along
with the second element and so on. Return the final result.
If the input function is
ExampleMaking the sum of squares for the first 5 natural numbers
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val fold<'T,'State> : folder: ('State -> 'T -> 'State) -> state: 'State -> list: 'T list -> 'State
val s: int
val v: int
ExampleShopping for fruits hungry, you tend to take more of each as the hunger grows
type Fruit =
| Apple
| Pear
| Orange
type BagItem =
{
fruit: Fruit
quantity: int
}
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val takeMore: previous: BagItem list -> fruit: Fruit -> BagItem list
val previous: BagItem list
type 'T list = List<'T>
val fruit: Fruit
val toTakeThisTime: int
val bagItem: BagItem
val otherBagItems: BagItem list
BagItem.quantity: int
val inputs: Fruit list
union case Fruit.Apple: Fruit
union case Fruit.Pear: Fruit
union case Fruit.Orange: Fruit
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val fold<'T,'State> : folder: ('State -> 'T -> 'State) -> state: 'State -> list: 'T list -> 'State
Evaluates to
|
||||
Full Usage:
List.fold2 folder state list1 list2
Parameters:
'State -> 'T1 -> 'T2 -> 'State
-
The function to update the state given the input elements.
state : 'State
-
The initial state.
list1 : 'T1 list
-
The first input list.
list2 : 'T2 list
-
The second input list.
Returns: 'State
The final state value.
|
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val fold2<'T1,'T2,'State> : folder: ('State -> 'T1 -> 'T2 -> 'State) -> state: 'State -> list1: 'T1 list -> list2: 'T2 list -> 'State
Evaluates to 1 . Note acc is a commonly used abbreviation for "accumulator".
|
||||
Full Usage:
List.foldBack folder list state
Parameters:
'T -> 'State -> 'State
-
The function to update the state given the input elements.
list : 'T list
-
The input list.
state : 'State
-
The initial state.
Returns: 'State
The state object after the folding function is applied to each element of the list.
|
ExampleMaking the sum of squares for the first 5 natural numbers
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val foldBack: folder: ('T -> 'State -> 'State) -> list: 'T list -> state: 'State -> 'State
val v: int
val acc: int
Note acc is a commonly used abbreviation for "accumulator".
ExampleShopping for fruits hungry, you tend to take more of each as the hunger grows
type Fruit =
| Apple
| Pear
| Orange
type BagItem =
{
fruit: Fruit
quantity: int
}
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val takeMore: fruit: Fruit -> previous: BagItem list -> BagItem list
val fruit: Fruit
val previous: BagItem list
type 'T list = List<'T>
val toTakeThisTime: int
val bagItem: BagItem
val otherBagItems: BagItem list
BagItem.quantity: int
val input: Fruit list
union case Fruit.Apple: Fruit
union case Fruit.Pear: Fruit
union case Fruit.Orange: Fruit
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val foldBack: folder: ('T -> 'State -> 'State) -> list: 'T list -> state: 'State -> 'State
Evaluates to
|
||||
Full Usage:
List.foldBack2 folder list1 list2 state
Parameters:
'T1 -> 'T2 -> 'State -> 'State
-
The function to update the state given the input elements.
list1 : 'T1 list
-
The first input list.
list2 : 'T2 list
-
The second input list.
state : 'State
-
The initial state.
Returns: 'State
The final state value.
|
Example
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int namespace Microsoft.FSharp.Text
Multiple items
val string: value: 'T -> string -------------------- type string = System.String Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val foldBack2: folder: ('T1 -> 'T2 -> 'State -> 'State) -> list1: 'T1 list -> list2: 'T2 list -> state: 'State -> 'State
Evaluates to
namespace Microsoft.FSharp.Text
Note acc is a commonly used abbreviation for "accumulator".
|
||||
|
The predicate is applied to the elements of the input list. If any application returns false then the overall result is false and no further elements are tested. Otherwise, true is returned.
Example
val isEven: a: int -> bool
val a: int
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val forall: predicate: ('T -> bool) -> list: 'T list -> bool
|
||||
|
The predicate is applied to matching elements in the two collections up to the lesser of the two lengths of the collections. If any application returns false then the overall result is false and no further elements are tested. Otherwise, if one collection is longer than the other then the ArgumentException exception is raised. Otherwise, true is returned.
Example
val inputs1: int list
val inputs2: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val forall2: predicate: ('T1 -> 'T2 -> bool) -> list1: 'T1 list -> list2: 'T2 list -> bool
Evaluates to true .
Example
val items1: int list
val items2: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val forall2: predicate: ('T1 -> 'T2 -> bool) -> list1: 'T1 list -> list2: 'T2 list -> bool
Evaluates to false .
Example
val items1: int list
val items2: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val forall2: predicate: ('T1 -> 'T2 -> bool) -> list1: 'T1 list -> list2: 'T2 list -> bool
Throws ArgumentException .
|
||||
|
Example
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val groupBy: projection: ('T -> 'Key) -> list: 'T list -> ('Key * 'T list) list (requires equality)
val n: int
Evaluates to [(1, [1; 3; 5]); (0, [2; 4])]
|
||||
Full Usage:
List.head list
Parameters:
'T list
-
The input list.
Returns: 'T
The first element of the list.
|
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val head: list: 'T list -> 'T
Evaluates to banana
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val head: list: 'T list -> 'T
Throws ArgumentException
|
||||
|
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val indexed: list: 'T list -> (int * 'T) list
Evaluates to [(0, "a"); (1, "b"); (2, "c")]
|
||||
|
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val init: length: int -> initializer: (int -> 'T) -> 'T list
val v: int
Evaluates to [5; 6; 7; 8]
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val init: length: int -> initializer: (int -> 'T) -> 'T list
val v: int
Throws ArgumentException
|
||||
|
Example
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val insertAt: index: int -> value: 'T -> source: 'T list -> 'T list
Evaluates to [ 0; 9; 1; 2 ] .
|
||||
|
Example
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val insertManyAt: index: int -> values: 'T seq -> source: 'T list -> 'T list
|
||||
|
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val isEmpty: list: 'T list -> bool
Evaluates to true
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val isEmpty: list: 'T list -> bool
Evaluates to false
|
||||
|
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val item: index: int -> list: 'T list -> 'T
Evaluates to "b"
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val item: index: int -> list: 'T list -> 'T
Throws ArgumentException
|
||||
|
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val iter: action: ('T -> unit) -> list: 'T list -> unit
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Evaluates to unit and prints
in the console.
|
||||
|
Example
val inputs1: string list
val inputs2: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val iter2: action: ('T1 -> 'T2 -> unit) -> list1: 'T1 list -> list2: 'T2 list -> unit
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Evaluates to unit and prints
in the console.
|
||||
|
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val iteri: action: (int -> 'T -> unit) -> list: 'T list -> unit
val i: int
val v: string
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Evaluates to unit and prints
in the console.
|
||||
|
Example
val inputs1: string list
val inputs2: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val iteri2: action: (int -> 'T1 -> 'T2 -> unit) -> list1: 'T1 list -> list2: 'T2 list -> unit
val i: int
val s1: string
val s2: string
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Evaluates to unit and prints
in the console.
|
||||
Full Usage:
List.last list
Parameters:
'T list
-
The input list.
Returns: 'T
The last element of the list.
|
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val last: list: 'T list -> 'T
Evaluates to banana
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val last: list: 'T list -> 'T
Throws ArgumentException
|
||||
|
The notation
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val length: list: 'T list -> int
Evaluates to 3
|
||||
|
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val map: mapping: ('T -> 'U) -> list: 'T list -> 'U list
val x: string
property System.String.Length: int with get
Evaluates to [ 1; 3; 2 ]
|
||||
|
Example
val inputs1: string list
val inputs2: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val map2: mapping: ('T1 -> 'T2 -> 'U) -> list1: 'T1 list -> list2: 'T2 list -> 'U list
val x: string
val y: int
Evaluates to seq ['a'; 'd'; 'o']
|
||||
Full Usage:
List.map3 mapping list1 list2 list3
Parameters:
'T1 -> 'T2 -> 'T3 -> 'U
-
The function to transform triples of elements from the input lists.
list1 : 'T1 list
-
The first input list.
list2 : 'T2 list
-
The second input list.
list3 : 'T3 list
-
The third input list.
Returns: 'U list
The list of transformed elements.
|
Example
val inputs1: string list
val inputs2: string list
val inputs3: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val map3: mapping: ('T1 -> 'T2 -> 'T3 -> 'U) -> list1: 'T1 list -> list2: 'T2 list -> list3: 'T3 list -> 'U list
val x: string
val y: string
val z: string
Evaluates to [ "all"; "the"; "time" ]
|
||||
Full Usage:
List.mapFold mapping state list
Parameters:
'State -> 'T -> 'Result * 'State
-
The function to transform elements from the input list and accumulate the final value.
state : 'State
-
The initial state.
list : 'T list
-
The input list.
Returns: 'Result list * 'State
The list of transformed elements, and the final accumulated value.
|
ExampleAccumulate the charges, and double them as well
type Charge =
| In of int
| Out of int
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val inputs: Charge list
union case Charge.In: int -> Charge
union case Charge.Out: int -> Charge
val newCharges: Charge list
val balance: int
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val mapFold<'T,'State,'Result> : mapping: ('State -> 'T -> 'Result * 'State) -> state: 'State -> list: 'T list -> 'Result list * 'State
val acc: int
val charge: Charge
val i: int
val o: int
Evaluates newCharges to [In 2; Out 4; In 6] and balance to 2 .
Note acc is a commonly used abbreviation for "accumulator".
|
||||
Full Usage:
List.mapFoldBack mapping list state
Parameters:
'T -> 'State -> 'Result * 'State
-
The function to transform elements from the input list and accumulate the final value.
list : 'T list
-
The input list.
state : 'State
-
The initial state.
Returns: 'Result list * 'State
The list of transformed elements, and the final accumulated value.
|
ExampleAccumulate the charges from back to front, and double them as well
type Charge =
| In of int
| Out of int
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val charges: Charge list
union case Charge.In: int -> Charge
union case Charge.Out: int -> Charge
val newCharges: Charge list
val balance: int
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val mapFoldBack: mapping: ('T -> 'State -> 'Result * 'State) -> list: 'T list -> state: 'State -> 'Result list * 'State
val charge: Charge
val acc: int
val i: int
val o: int
Evaluates newCharges to [In 2; Out 4; In 6] and balance to 2 .
Note acc is a commonly used abbreviation for "accumulator".
|
||||
|
Example
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val mapi: mapping: (int -> 'T -> 'U) -> list: 'T list -> 'U list
val i: int
val x: int
Evaluates to [ 10; 11; 12 ]
|
||||
Full Usage:
List.mapi2 mapping list1 list2
Parameters:
int -> 'T1 -> 'T2 -> 'U
-
The function to transform pairs of elements from the two lists and their index.
list1 : 'T1 list
-
The first input list.
list2 : 'T2 list
-
The second input list.
Returns: 'U list
The list of transformed elements.
|
Example
val inputs1: string list
val inputs2: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val mapi2: mapping: (int -> 'T1 -> 'T2 -> 'U) -> list1: 'T1 list -> list2: 'T2 list -> 'U list
val i: int
val x: string
val y: int
Evaluates to [(0, 'a'); (1, 'd'); (2, 'o')]
|
||||
Full Usage:
List.max list
Parameters:
'T list
-
The input list.
Returns: 'T
The maximum element.
Modifiers: inline Type parameters: 'T |
Raises ArgumentException if
Example
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val max: list: 'T list -> 'T (requires comparison)
Evaluates to 12
Example
val inputs: 'a list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val max: list: 'T list -> 'T (requires comparison)
Throws System.ArgumentException .
|
||||
Full Usage:
List.maxBy projection list
Parameters:
'T -> 'U
-
The function to transform the list elements into the type to be compared.
list : 'T list
-
The input list.
Returns: 'T
The maximum element.
Modifiers: inline Type parameters: 'T, 'U |
Raises ArgumentException if
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val maxBy: projection: ('T -> 'U) -> list: 'T list -> 'T (requires comparison)
val s: string
property System.String.Length: int with get
Evaluates to "cccc"
Example
val inputs: 'a list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val maxBy: projection: ('T -> 'U) -> list: 'T list -> 'T (requires comparison)
val s: string
Multiple items
val string: value: 'T -> string -------------------- type string = System.String property System.String.Length: int with get
Throws System.ArgumentException .
|
||||
Full Usage:
List.min list
Parameters:
'T list
-
The input list.
Returns: 'T
The minimum value.
Modifiers: inline Type parameters: 'T |
Raises ArgumentException if
Example
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val min: list: 'T list -> 'T (requires comparison)
Evaluates to 10
Example
val inputs: 'a list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val min: list: 'T list -> 'T (requires comparison)
Throws System.ArgumentException .
|
||||
Full Usage:
List.minBy projection list
Parameters:
'T -> 'U
-
The function to transform list elements into the type to be compared.
list : 'T list
-
The input list.
Returns: 'T
The minimum value.
Modifiers: inline Type parameters: 'T, 'U |
Raises ArgumentException if
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val minBy: projection: ('T -> 'U) -> list: 'T list -> 'T (requires comparison)
val s: string
property System.String.Length: int with get
Evaluates to "b"
Example
val inputs: 'a list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val minBy: projection: ('T -> 'U) -> list: 'T list -> 'T (requires comparison)
val s: string
Multiple items
val string: value: 'T -> string -------------------- type string = System.String property System.String.Length: int with get
Throws System.ArgumentException .
|
||||
Full Usage:
List.ofArray array
Parameters:
'T[]
-
The input array.
Returns: 'T list
The list of elements from the array.
|
Example
val inputs: int array
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val ofArray: array: 'T array -> 'T list
Evaluates to [ 1; 2; 5 ] .
|
||||
|
Example
val inputs: int seq
Multiple items
val seq: sequence: 'T seq -> 'T seq -------------------- type 'T seq = System.Collections.Generic.IEnumerable<'T> Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val ofSeq: source: 'T seq -> 'T list
Evaluates to [ 1; 2; 5 ] .
|
||||
|
Example
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val pairwise: list: 'T list -> ('T * 'T) list
Evaluates to [(1, 2); (2, 3); (3, 4)] .
|
||||
Example
val inputs: int list
val evens: int list
val odds: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val partition: predicate: ('T -> bool) -> list: 'T list -> 'T list * 'T list
val x: int
Evaluates evens to [2; 4] and odds to [1; 3] .
|
|||||
|
Example
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val permute: indexMap: (int -> int) -> list: 'T list -> 'T list
val x: int
Evaluates to [4; 1; 2; 3] .
|
||||
|
Applies the given function to successive elements, returning the first
result where function returns
Example
val input: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val pick: chooser: ('T -> 'U option) -> list: 'T list -> 'U
val n: int
union case Option.Some: Value: 'T -> Option<'T>
Multiple items
val string: value: 'T -> string -------------------- type string = System.String union case Option.None: Option<'T>
Evaluates to "2" .
Example
val input: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val pick: chooser: ('T -> 'U option) -> list: 'T list -> 'U
val n: int
union case Option.Some: Value: 'T -> Option<'T>
Multiple items
val string: value: 'T -> string -------------------- type string = System.String union case Option.None: Option<'T>
Throws KeyNotFoundException .
|
||||
Full Usage:
List.reduce reduction list
Parameters:
'T -> 'T -> 'T
-
The function to reduce two list elements to a single element.
list : 'T list
-
The input list.
Returns: 'T
The final reduced value.
|
Apply a function to each element of the collection, threading an accumulator argument
through the computation. Apply the function to the first two elements of the list.
Then feed this result into the function along with the third element and so on.
Return the final result. If the input function is
Raises ArgumentException if
Example
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val reduce: reduction: ('T -> 'T -> 'T) -> list: 'T list -> 'T
val a: int
val b: int
Evaluates to 1342 , by computing ((1 * 10 + 3) * 10 + 4) * 10 + 2
|
||||
Full Usage:
List.reduceBack reduction list
Parameters:
'T -> 'T -> 'T
-
A function that takes in the next-to-last element of the list and the
current accumulated result to produce the next accumulated result.
list : 'T list
-
The input list.
Returns: 'T
The final result of the reductions.
|
Example
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val reduceBack: reduction: ('T -> 'T -> 'T) -> list: 'T list -> 'T
val a: int
val b: int
Evaluates to 2431 , by computing 1 + (3 + (4 + 2 * 10) * 10) * 10
|
||||
|
Example
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val removeAt: index: int -> source: 'T list -> 'T list
let inputs = [ 0; 2 ]
|
||||
|
Example
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val removeManyAt: index: int -> count: int -> source: 'T list -> 'T list
Evaluates to [ 0; 3 ] .
|
||||
|
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val replicate: count: int -> initial: 'T -> 'T list
Evaluates to [ "a"; "a"; "a" ] .
|
||||
|
Example
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val rev: list: 'T list -> 'T list
Evaluates to [ 2; 1; 0 ] .
|
||||
|
Applies a function to each element of the collection, threading an accumulator argument through the computation. Take the second argument, and apply the function to it and the first element of the list. Then feed this result into the function along with the second element and so on. Returns the list of intermediate results and the final result.
ExampleApply a list charges and collect the running balances as each is applied:
type Charge =
| In of int
| Out of int
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val inputs: Charge list
union case Charge.In: int -> Charge
union case Charge.Out: int -> Charge
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val scan<'T,'State> : folder: ('State -> 'T -> 'State) -> state: 'State -> list: 'T list -> 'State list
val acc: int
val charge: Charge
val i: int
val o: int
Evaluates to [0; 1; -1; 2] . Note 0 is the initial
state, 1 the next state, -1 the next state, and 2 the final state.
Note acc is a commonly used abbreviation for "accumulator".
|
||||
|
ExampleApply a list charges from back to front, and collect the running balances as each is applied:
type Charge =
| In of int
| Out of int
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val inputs: Charge list
union case Charge.In: int -> Charge
union case Charge.Out: int -> Charge
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val scanBack: folder: ('T -> 'State -> 'State) -> list: 'T list -> state: 'State -> 'State list
val charge: Charge
val acc: int
val i: int
val o: int
Evaluates to [2; 1; 3; 0] by processing each input from back to front. Note 0 is the initial
state, 3 the next state, 1 the next state, and 2 the final state, and the states
are produced from back to front.
Note acc is a commonly used abbreviation for "accumulator".
|
||||
Full Usage:
List.singleton value
Parameters:
'T
-
The input item.
Returns: 'T list
The result list of one item.
Modifiers: inline Type parameters: 'T |
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val singleton: value: 'T -> 'T list
Evaluates to [ 7 ] .
|
||||
|
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val skip: count: int -> list: 'T list -> 'T list
Evaluates to ["c"; "d"]
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val skip: count: int -> list: 'T list -> 'T list
Throws ArgumentException .
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val skip: count: int -> list: 'T list -> 'T list
Evaluates to ["a"; "b"; "c"; "d"] .
|
||||
|
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val skipWhile: predicate: ('T -> bool) -> list: 'T list -> 'T list
val x: string
property System.String.Length: int with get
Evaluates to ["bbb"; "cc"; "d"]
|
||||
|
This is a stable sort, i.e. the original order of equal elements is preserved.
Example
val input: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val sort: list: 'T list -> 'T list (requires comparison)
Evaluates to [1; 1 3; 4; 6; 8] .
|
||||
|
Sorts the given list using keys given by the given projection. Keys are compared using Operators.compare. This is a stable sort, i.e. the original order of equal elements is preserved.
Example
val input: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val sortBy: projection: ('T -> 'Key) -> list: 'T list -> 'T list (requires comparison)
val s: string
property System.String.Length: int with get
Evaluates to ["a"; "dd"; "bbb"; "cccc"] .
|
||||
|
Sorts the given list in descending order using keys given by the given projection. Keys are compared using Operators.compare. This is a stable sort, i.e. the original order of equal elements is preserved.
Example
val input: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val sortByDescending: projection: ('T -> 'Key) -> list: 'T list -> 'T list (requires comparison)
val s: string
property System.String.Length: int with get
Evaluates to ["cccc"; "bbb"; "dd"; "a"] .
|
||||
|
This is a stable sort, i.e. the original order of equal elements is preserved.
Example
val input: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val sortDescending: list: 'T list -> 'T list (requires comparison)
Evaluates to [8; 6; 4; 3; 1; 1] .
|
||||
|
This is a stable sort, i.e. the original order of equal elements is preserved.
ExampleSort a list of pairs using a comparison function that compares string lengths then index numbers:
val compareEntries: n1: int * s1: string -> n2: int * s2: string -> int
val n1: int
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val s1: string
Multiple items
val string: value: 'T -> string -------------------- type string = System.String val n2: int
val s2: string
val c: int
val compare: e1: 'T -> e2: 'T -> int (requires comparison)
property System.String.Length: int with get
val input: (int * string) list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val sortWith: comparer: ('T -> 'T -> int) -> list: 'T list -> 'T list
Evaluates to [(0, "aa"); (2, "cc"); (3, "dd"); (1, "bbb")] .
|
||||
|
Example
val input: int list
val front: int list
val back: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val splitAt: index: int -> list: 'T list -> 'T list * 'T list
Evaluates front to [8; 4; 3] and back to [1; 6; 1] .
|
||||
|
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val splitInto: count: int -> list: 'T list -> 'T list list
Evaluates to [[1; 2; 3; 4; 5]; [6; 7; 8; 9; 10]] .
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val splitInto: count: int -> list: 'T list -> 'T list list
Evaluates to [[1; 2; 3]; [4; 5; 6]; [7; 8]; [9; 10]] .
|
||||
Full Usage:
List.sum list
Parameters:
^T list
-
The input list.
Returns: ^T
The resulting sum.
Modifiers: inline Type parameters: ^T |
Example
val input: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val sum: list: 'T list -> 'T (requires member (+) and member Zero)
Evaluates to 11 .
|
||||
Full Usage:
List.sumBy projection list
Parameters:
'T -> ^U
-
The function to transform the list elements into the type to be summed.
list : 'T list
-
The input list.
Returns: ^U
The resulting sum.
Modifiers: inline Type parameters: 'T, ^U |
Example
val input: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val sumBy: projection: ('T -> 'U) -> list: 'T list -> 'U (requires member (+) and member Zero)
val s: string
property System.String.Length: int with get
Evaluates to 7 .
|
||||
|
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val tail: list: 'T list -> 'T list
Evaluates to ["bb"; "ccc"]
|
||||
|
Throws
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val take: count: int -> list: 'T list -> 'T list
Evaluates to ["a"; "b"]
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val take: count: int -> list: 'T list -> 'T list
Throws InvalidOperationException .
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val take: count: int -> list: 'T list -> 'T list
Evaluates to the empty list.
|
||||
|
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val takeWhile: predicate: ('T -> bool) -> list: 'T list -> 'T list
val x: string
property System.String.Length: int with get
Evaluates to ["a"; "bb"]
|
||||
Full Usage:
List.toArray list
Parameters:
'T list
-
The input list.
Returns: 'T[]
The array containing the elements of the list.
|
Example
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val toArray: list: 'T list -> 'T array
Evaluates to [| 1; 2; 5 |] .
|
||||
|
Example
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val toSeq: list: 'T list -> 'T seq
Evaluates to seq { 1; 2; 5 } .
|
||||
|
Example
val inputs: int list list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val transpose: lists: 'T list seq -> 'T list list
Evaluates to [ [10; 11]; [20; 21]; [30; 31] ] .
|
||||
|
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val truncate: count: int -> list: 'T list -> 'T list
Evaluates to ["a"; "b"]
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val truncate: count: int -> list: 'T list -> 'T list
Evaluates to ["a"; "b"; "c"; "d"]
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val truncate: count: int -> list: 'T list -> 'T list
Evaluates to the empty list.
|
||||
|
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val tryExactlyOne: list: 'T list -> 'T option
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int type 'T list = List<'T>
|
||||
|
ExampleTry to find the first even number:
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val tryFind: predicate: ('T -> bool) -> list: 'T list -> 'T option
val elm: int
Evaluates to Some 2
ExampleTry to find the first even number:
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val tryFind: predicate: ('T -> bool) -> list: 'T list -> 'T option
val elm: int
Evaluates to None
|
||||
|
ExampleTry to find the first even number from the back:
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val tryFindBack: predicate: ('T -> bool) -> list: 'T list -> 'T option
val elm: int
Evaluates to Some 4
ExampleTry to find the first even number from the back:
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val tryFindBack: predicate: ('T -> bool) -> list: 'T list -> 'T option
val elm: int
Evaluates to None
|
||||
|
ExampleTry to find the index of the first even number:
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val tryFindIndex: predicate: ('T -> bool) -> list: 'T list -> int option
val elm: int
Evaluates to Some 1
ExampleTry to find the index of the first even number:
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val tryFindIndex: predicate: ('T -> bool) -> list: 'T list -> int option
val elm: int
Evaluates to None
|
||||
|
ExampleTry to find the index of the first even number from the back:
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val tryFindIndexBack: predicate: ('T -> bool) -> list: 'T list -> int option
val elm: int
Evaluates to Some 3
ExampleTry to find the index of the first even number from the back:
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val tryFindIndexBack: predicate: ('T -> bool) -> list: 'T list -> int option
val elm: int
Evaluates to None
|
||||
|
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val tryHead: list: 'T list -> 'T option
Evaluates to Some "banana"
Example
val inputs: int list
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int type 'T list = List<'T>
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val tryHead: list: 'T list -> 'T option
Evaluates to None
|
||||
|
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val tryItem: index: int -> list: 'T list -> 'T option
Evaluates to Some "b" .
Example
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val tryItem: index: int -> list: 'T list -> 'T option
Evaluates to None .
|
||||
|
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val tryLast: list: 'T list -> 'T option
Evaluates to Some "banana"
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val tryLast: list: 'T list -> 'T option
Evaluates to None
|
||||
|
Example
val input: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val tryPick: chooser: ('T -> 'U option) -> list: 'T list -> 'U option
val n: int
union case Option.Some: Value: 'T -> Option<'T>
Multiple items
val string: value: 'T -> string -------------------- type string = System.String union case Option.None: Option<'T>
Evaluates to Some "2" .
Example
val input: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val tryPick: chooser: ('T -> 'U option) -> list: 'T list -> 'U option
val n: int
union case Option.Some: Value: 'T -> Option<'T>
Multiple items
val string: value: 'T -> string -------------------- type string = System.String union case Option.None: Option<'T>
Evaluates to None .
|
||||
Full Usage:
List.unfold generator state
Parameters:
'State -> ('T * 'State) option
-
A function that takes in the current state and returns an option tuple of the next
element of the list and the next state value.
state : 'State
-
The initial state value.
Returns: 'T list
The result list.
|
Example
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val unfold<'T,'State> : generator: ('State -> ('T * 'State) option) -> state: 'State -> 'T list
val state: int
union case Option.None: Option<'T>
union case Option.Some: Value: 'T -> Option<'T>
Evaluates to [1; 2; 4; 8; 16; 32; 64]
|
||||
|
Example
val inputs: (int * string) list
val numbers: int list
val names: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val unzip: list: ('T1 * 'T2) list -> 'T1 list * 'T2 list
Evaluates numbers to [1; 2] and names to ["one"; "two"] .
|
||||
|
Example
val inputs: (int * string * string) list
val numbers: int list
val names: string list
val roman: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val unzip3: list: ('T1 * 'T2 * 'T3) list -> 'T1 list * 'T2 list * 'T3 list
Evaluates numbers to [1; 2] , names to ["one"; "two"] and roman to ["I"; "II"] .
|
||||
|
Example
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val updateAt: index: int -> value: 'T -> source: 'T list -> 'T list
Evaluates to [ 0; 9; 2 ] .
|
||||
|
This is identical to
ExampleSelect only the even numbers:
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val where: predicate: ('T -> bool) -> list: 'T list -> 'T list
val elm: int
Evaluates to [2; 4]
|
||||
|
Example
val inputs: int list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val windowed: windowSize: int -> list: 'T list -> 'T list list
Evaluates to [[1; 2; 3]; [2; 3; 4]; [3; 4; 5]]
|
||||
|
Example
val numbers: int list
val names: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val zip: list1: 'T1 list -> list2: 'T2 list -> ('T1 * 'T2) list
Evaluates to [(1, "one"); (2, "two")] .
|
||||
|
Example
val numbers: int list
val names: string list
val roman: string list
Multiple items
module List from Microsoft.FSharp.Collections -------------------- type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ... val zip3: list1: 'T1 list -> list2: 'T2 list -> list3: 'T3 list -> ('T1 * 'T2 * 'T3) list
Evaluates to [(1, "one", "I"); (2, "two", "II")] .
|