Header menu logo FSharp.Core

List Module

Contains operations for working with values of type list.

Functions and values

Function or value Description

List.allPairs list1 list2

Full Usage: List.allPairs list1 list2

Parameters:
    list1 : 'T1 list - The first input list.
    list2 : 'T2 list - The second input list.

Returns: ('T1 * 'T2) list The resulting list of pairs.

Returns a new list that contains all pairings of elements from two lists.

list1 : 'T1 list

The first input list.

list2 : 'T2 list

The second input list.

Returns: ('T1 * 'T2) list

The resulting list of pairs.

Example

 let people = [ "Kirk"; "Spock"; "McCoy" ]
 let numbers = [ 1; 2 ]

 people |> List.allPairs numbers
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
 [ (1, "Kirk"); (1, "Spock"); (1, "McCoy"); (2, "Kirk"); (2, "Spock"); (2, "McCoy") ]

List.append list1 list2

Full Usage: List.append list1 list2

Parameters:
    list1 : 'T list - The first input list.
    list2 : 'T list - The second input list.

Returns: 'T list The resulting list.

Returns a new list that contains the elements of the first list followed by elements of the second list.

list1 : 'T list

The first input list.

list2 : 'T list

The second input list.

Returns: 'T list

The resulting list.

Example

 List.append [ 1..3 ] [ 4..7 ]
 
 [ 4..7 ] |> List.append [ 1..3 ]
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
 [ 1; 2; 3; 4; 5; 6; 7 ]

List.average list

Full Usage: List.average list

Parameters:
    list : ^T list - The input list.

Returns: ^T The resulting average.
Modifiers: inline
Type parameters: ^T

Returns the average of the values in a non-empty list.

list : ^T list

The input list.

Returns: ^T

The resulting average.

ArgumentException Thrown when the input list is empty.
Example

 [1.0 .. 9.0] |> List.average
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
 5.0

List.averageBy projection list

Full Usage: List.averageBy projection list

Parameters:
    projection : '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

Returns the average of values in a list generated by applying a function to each element of the list.

projection : '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.

ArgumentException Thrown when the list is empty.
Example

Calculate average age of persons by extracting their age from a record type.

 type People = { Name: string; Age: int }

 let getAgeAsFloat person = float person.Age

 let people = 
     [ { Name = "Kirk"; Age = 26 }
       { Name = "Spock"; Age = 90 }
       { Name = "McCoy"; Age = 37 } ]

 people |> List.averageBy getAgeAsFloat
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
 51.0

List.choose chooser list

Full Usage: List.choose chooser list

Parameters:
    chooser : 'T -> 'U option - The function to be applied to the list elements.
    list : 'T list - The input list.

Returns: 'U list The resulting list comprising the values v where the chooser function returned Some(x).

Applies a function to each element in a list and then returns a list of values v where the applied function returned Some(v). Returns an empty list when the input list is empty or when the applied chooser function returns None for all elements.

chooser : 'T -> 'U option

The function to be applied to the list elements.

list : 'T list

The input list.

Returns: 'U list

The resulting list comprising the values v where the chooser function returned Some(x).

Example

Using the identity function id (is defined like fun x -> x):

 
 let input1 = [ Some 1; None; Some 3; None ]

 input1 |> List.choose id
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
 [ 1; 3 ]

Example

 type Happiness =
     | AlwaysHappy
     | MostOfTheTimeGrumpy

 type People = { Name: string; Happiness: Happiness }

 let takeJustHappyPersons person =
     match person.Happiness with
     | AlwaysHappy -> Some person.Name
     | MostOfTheTimeGrumpy -> None

 let candidatesForTheTrip = 
     [ { Name = "SpongeBob"
         Happiness = AlwaysHappy }
       { Name = "Patrick"
         Happiness = AlwaysHappy }
       { Name = "Squidward"
         Happiness = MostOfTheTimeGrumpy } ]

 candidatesForTheTrip
 |> List.choose takeJustHappyPersons
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
 [ "SpongeBob"; "Patrick" ]

Example

 let input3: int option list = [] 

 input3 |> List.choose id
 Evaluates to:
 empty list
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

 let input4: string option list = [None; None]

 input4 |> List.choose id
 Evaluates to
 empty list
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 id (is defined like fun x -> x):

 
 let input5 = [ Some 1; None; Some 3; None ]

 input5 |> List.choose id  // evaluates [1; 3]
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

List.chunkBySize chunkSize list

Full Usage: List.chunkBySize chunkSize list

Parameters:
    chunkSize : int - The maximum size of each chunk.
    list : 'T list - The input list.

Returns: 'T list list The list divided into chunks.

Divides the input list into lists (chunks) of size at most chunkSize. Returns a new list containing the generated lists (chunks) as its elements. Returns an empty list when the input list is empty.

chunkSize : int

The maximum size of each chunk.

list : 'T list

The input list.

Returns: 'T list list

The list divided into chunks.

ArgumentException Thrown when chunkSize is not positive.
Example

 [ 1..10 ] |> List.chunkBySize 3
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
 [ [ 1; 2; 3 ]
   [ 4; 5; 6 ]
   [ 7; 8; 9 ]
   [ 10 ] ]

Example

 [ 1..5 ] |> List.chunkBySize 10
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
 [ [ 1; 2; 3; 4; 5 ] ]

List.collect mapping list

Full Usage: List.collect mapping list

Parameters:
    mapping : 'T -> 'U list - The function to transform each input element into a sublist to be concatenated.
    list : 'T list - The input list.

Returns: 'U list The concatenation of the transformed sublists.

For each element of the list, applies the given function. Concatenates all the results and returns the combined list.

mapping : 'T -> 'U list

The function to transform each input element into a sublist to be concatenated.

list : 'T list

The input list.

Returns: 'U list

The concatenation of the transformed sublists.

Example

For each positive number in the array we are generating all the previous positive numbers

 [1..4] |> List.collect (fun x -> [1..x])
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)

List.compareWith comparer list1 list2

Full Usage: List.compareWith comparer list1 list2

Parameters:
    comparer : '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

Compares two lists using the given comparison function, element by element.

comparer : '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.

Example

 let closerToNextDozen a b =
   (a % 12).CompareTo(b % 12)

 let input1 = [1; 10]
 let input2 = [1; 10]

 (input1, input2) ||> List.compareWith closerToNextDozen
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

 let closerToNextDozen a b =
   (a % 12).CompareTo(b % 12)

 let input1 = [1; 5]
 let input2 = [1; 8]

 (input1, input2) ||> List.compareWith closerToNextDozen
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

 let closerToNextDozen a b =
   (a % 12).CompareTo(b % 12)

 let input1 = [1; 11]
 let input2 = [1; 13]

 (input1, input2) ||> List.compareWith closerToNextDozen
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

 let closerToNextDozen a b =
   (a % 12).CompareTo(b % 12)

 let input1 = [1; 2]
 let input2 = [1]

 (input1, input2) ||> List.compareWith closerToNextDozen
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

 let closerToNextDozen a b =
   (a % 12).CompareTo(b % 12)

 let input1 = [1]
 let input2 = [1; 2]

 (input1, input2) ||> List.compareWith closerToNextDozen
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

List.concat lists

Full Usage: List.concat lists

Parameters:
    lists : 'T list seq - The input sequence of lists.

Returns: 'T list The resulting concatenated list.

Returns a new list that contains the elements of each of the lists in order.

lists : 'T list seq

The input sequence of lists.

Returns: 'T list

The resulting concatenated list.

Example

 let input = [ [1;2]
               [3;4;5]
               [6;7;8;9] ]
 input |> List.concat  // evaluates [1; 2; 3; 4; 5; 6; 7; 8; 9]
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

List.contains value source

Full Usage: List.contains value source

Parameters:
    value : 'T - The value to locate in the input list.
    source : 'T list - The input list.

Returns: bool True if the input list contains the specified element; false otherwise.
Modifiers: inline
Type parameters: 'T

Tests if the list contains the specified element.

value : 'T

The value to locate in the input list.

source : 'T list

The input list.

Returns: bool

True if the input list contains the specified element; false otherwise.

Example

 [1..9] |> List.contains 0
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

 [1..9] |> List.contains 3
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

 let input = [1, "SpongeBob"; 2, "Patrick"; 3, "Squidward"; 4, "Mr. Krabs"]

 input |> List.contains (2, "Patrick")
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

 let input = [1, "SpongeBob"; 2, "Patrick"; 3, "Squidward"; 4, "Mr. Krabs"]

 input |> List.contains (22, "Patrick")
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.

List.countBy projection list

Full Usage: List.countBy projection list

Parameters:
    projection : 'T -> 'Key - A function transforming each item of the input list into a key to be compared against the others.
    list : 'T list - The input list.

Returns: ('Key * int) list The result list.

Applies a key-generating function to each element of a list and returns a list yielding unique keys and their number of occurrences in the original list.

projection : 'T -> 'Key

A function transforming each item of the input list into a key to be compared against the others.

list : 'T list

The input list.

Returns: ('Key * int) list

The result list.

Example

Counting the number of occurrences of chars

 let input = ['H'; 'a'; 'p'; 'p'; 'y']

 input |> List.countBy id
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)]

List.distinct list

Full Usage: List.distinct list

Parameters:
    list : 'T list - The input list.

Returns: 'T list The result list.

Returns a list that contains no duplicate entries according to generic hash and equality comparisons on the entries. If an element occurs multiple times in the list then the later occurrences are discarded.

list : 'T list

The input list.

Returns: 'T list

The result list.

Example

 let input = [6;1;2;3;1;4;5;5]

 input |> List.distinct
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].

List.distinctBy projection list

Full Usage: List.distinctBy projection list

Parameters:
    projection : 'T -> 'Key - A function transforming the list items into comparable keys.
    list : 'T list - The input list.

Returns: 'T list The result list.

Returns a list that contains no duplicate entries according to the generic hash and equality comparisons on the keys returned by the given key-generating function. If an element occurs multiple times in the list then the later occurrences are discarded.

projection : 'T -> 'Key

A function transforming the list items into comparable keys.

list : 'T list

The input list.

Returns: 'T list

The result list.

Example

 let isEven x = 0 = x % 2

 let input = [6;1;2;3;1;4;5;5]

 input |> List.distinctBy isEven  // evaluates [6; 1]
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)

List.empty

Full Usage: List.empty

Returns: 'T list

Returns an empty list of the given type.

Returns: 'T list

List.exactlyOne list

Full Usage: List.exactlyOne list

Parameters:
    list : 'T list - The input list.

Returns: 'T The only element of the list.

Returns the only element of the list.

list : 'T list

The input list.

Returns: 'T

The only element of the list.

ArgumentException Thrown when the input does not have precisely one element.
Example

 ["the chosen one"] |> List.exactlyOne // evaluates "the chosen one"
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

 let input : string list = []

 input |> List.exactlyOne
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

 [1..5] |> List.exactlyOne
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

List.except itemsToExclude list

Full Usage: List.except itemsToExclude list

Parameters:
    itemsToExclude : '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.

Returns a new list with the distinct elements of the input list which do not appear in the itemsToExclude sequence, using generic hash and equality comparisons to compare values.

itemsToExclude : '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.

ArgumentNullException Thrown when itemsToExclude is null.
Example

 let input = [1, "Kirk"; 2, "Spock"; 3, "Kenobi"] 

 input |> List.except [3, "Kenobi"]
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

 [0..10] |> List.except [1..5]  // evaluates [0; 6; 7; 8; 9; 10]
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

 [1..5] |> List.except [0..10]  // evaluates []
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)

List.exists predicate list

Full Usage: List.exists predicate list

Parameters:
    predicate : 'T -> bool - The function to test the input elements.
    list : 'T list - The input list.

Returns: bool True if any element satisfies the predicate.

Tests if any element of the list satisfies the given predicate.

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.

predicate : 'T -> bool

The function to test the input elements.

list : 'T list

The input list.

Returns: bool

True if any element satisfies the predicate.

Example

 let input = [1, "Kirk"; 2, "Spock"; 3, "Kenobi"] 
 
 input |> List.exists (fun x -> x = (3, "Kenobi"))  // evaluates true
 
 input |> List.exists (fun (n, name) -> n > 5)      // evaluates false
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

List.exists2 predicate list1 list2

Full Usage: List.exists2 predicate list1 list2

Parameters:
    predicate : 'T1 -> 'T2 -> bool - The function to test the input elements.
    list1 : 'T1 list - The first input list.
    list2 : 'T2 list - The second input list.

Returns: bool True if any pair of elements satisfy the predicate.

Tests if any pair of corresponding elements of the lists satisfies the given predicate.

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.

predicate : 'T1 -> 'T2 -> bool

The function to test the input elements.

list1 : 'T1 list

The first input list.

list2 : 'T2 list

The second input list.

Returns: bool

True if any pair of elements satisfy the predicate.

ArgumentException Thrown when the input lists differ in length.
Example

Check if the sum of pairs (from 2 different lists) have at least one even number

 let anEvenSum a b  = 0 = (a + b) % 2
 
 ([1..4], [2..5]) 
 ||> List.exists2 anEvenSum     // evaluates false
 
 ([1..4], [2;4;5;6])
 ||> List.exists2 anEvenSum   // evaluates true
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

List.filter predicate list

Full Usage: List.filter predicate list

Parameters:
    predicate : 'T -> bool - The function to test the input elements.
    list : 'T list - The input list.

Returns: 'T list A list containing only the elements that satisfy the predicate.

Returns a new collection containing only the elements of the collection for which the given predicate returns "true"

predicate : 'T -> bool

The function to test the input elements.

list : 'T list

The input list.

Returns: 'T list

A list containing only the elements that satisfy the predicate.

Example

 let input = [1, "Luke"; 2, "Kirk"; 3, "Kenobi"; 4, "Spock"]

 let isEven x = 0 = x % 2

 let isComingFromStarTrek (x,_) = isEven x
 
 input |> List.filter isComingFromStarTrek
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")]

List.find predicate list

Full Usage: List.find predicate list

Parameters:
    predicate : 'T -> bool - The function to test the input elements.
    list : 'T list - The input list.

Returns: 'T The first element that satisfies the predicate.

Returns the first element for which the given function returns True. Raises KeyNotFoundException if no such element exists.

predicate : 'T -> bool

The function to test the input elements.

list : 'T list

The input list.

Returns: 'T

The first element that satisfies the predicate.

KeyNotFoundException Thrown if the predicate evaluates to false for all the elements of the list.
Example

 let isEven x  = 0 = x % 2

 let isGreaterThan x y = y > x

 let input = [1, "Luke"; 2, "Kirk"; 3, "Spock"; 4, "Kenobi"]
 
 input |> List.find (fun (x,_) -> isEven x)              // evaluates (2, "Kirk")
 input |> List.find (fun (x,_) -> x |> isGreaterThan 6)  // raises an exception
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

List.findBack predicate list

Full Usage: List.findBack predicate list

Parameters:
    predicate : 'T -> bool - The function to test the input elements.
    list : 'T list - The input list.

Returns: 'T The last element that satisfies the predicate.

Returns the last element for which the given function returns True. Raises KeyNotFoundException if no such element exists.

predicate : 'T -> bool

The function to test the input elements.

list : 'T list

The input list.

Returns: 'T

The last element that satisfies the predicate.

KeyNotFoundException Thrown if the predicate evaluates to false for all the elements of the list.
Example

 let isEven x  = 0 = x % 2

 let isGreaterThan x y = y > x

 let input = [1, "Luke"; 2, "Kirk"; 3, "Spock"; 4, "Kenobi"]
 
 input |> List.findBack (fun (x,_) -> isEven x)              // evaluates (4, "Kenobi")
 input |> List.findBack (fun (x,_) -> x |> isGreaterThan 6)  // raises an exception
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

List.findIndex predicate list

Full Usage: List.findIndex predicate list

Parameters:
    predicate : 'T -> bool - The function to test the input elements.
    list : 'T list - The input list.

Returns: int The index of the first element that satisfies the predicate.

Returns the index of the first element in the list that satisfies the given predicate. Raises KeyNotFoundException if no such element exists.

predicate : 'T -> bool

The function to test the input elements.

list : 'T list

The input list.

Returns: int

The index of the first element that satisfies the predicate.

ArgumentException Thrown if the predicate evaluates to false for all the elements of the list.
Example

 let isEven x  = 0 = x % 2

 let isGreaterThan x y = y > x

 let input = [1, "Luke"; 2, "Kirk"; 3, "Spock"; 4, "Kenobi"]
 
 input |> List.findIndex (fun (x,_) -> isEven x)              // evaluates 1
 input |> List.findIndex (fun (x,_) -> x |> isGreaterThan 6)  // raises an exception
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

List.findIndexBack predicate list

Full Usage: List.findIndexBack predicate list

Parameters:
    predicate : 'T -> bool - The function to test the input elements.
    list : 'T list - The input list.

Returns: int The index of the last element that satisfies the predicate.

Returns the index of the last element in the list that satisfies the given predicate. Raises KeyNotFoundException if no such element exists.

predicate : 'T -> bool

The function to test the input elements.

list : 'T list

The input list.

Returns: int

The index of the last element that satisfies the predicate.

ArgumentException Thrown if the predicate evaluates to false for all the elements of the list.
Example

 let isEven x  = 0 = x % 2

 let isGreaterThan x y = y > x

 let input = [1, "Luke"; 2, "Kirk"; 3, "Spock"; 4, "Kenobi"]
 
 input |> List.findIndexBack (fun (x,_) -> isEven x)              // evaluates 3
 input |> List.findIndexBack (fun (x,_) -> x |> isGreaterThan 6)  // raises an exception
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

List.fold folder state list

Full Usage: List.fold folder state list

Parameters:
    folder : '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 f and the elements are i0...iN then computes f (... (f s i0) i1 ...) iN.

folder : '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.

Example

Making the sum of squares for the first 5 natural numbers

 (0, [1..5]) ||> List.fold (fun s v -> s + v * v)  // evaluates 55
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

Example

Shopping 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 }

 let takeMore (previous: BagItem list) fruit = 
     let toTakeThisTime = 
         match previous with 
         | bagItem :: otherBagItems -> bagItem.quantity + 1 
         | [] -> 1 
     { fruit = fruit; quantity = toTakeThisTime } :: previous

 let inputs = [ Apple; Pear; Orange ]
 
 ([], inputs) ||> List.fold takeMore
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
  [{ fruit = Orange; quantity = 3 }
   { fruit = Pear; quantity = 2 }
   { fruit = Apple; quantity = 1 }]

List.fold2 folder state list1 list2

Full Usage: List.fold2 folder state list1 list2

Parameters:
    folder : '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.

Applies a function to corresponding elements of two collections, threading an accumulator argument through the computation. The collections must have identical sizes. If the input function is f and the elements are i0...iN and j0...jN then computes f (... (f s i0 j0)...) iN jN.

folder : '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

Count the number of times the coins match:
 type CoinToss = Head | Tails

 let inputs1 = [Tails; Head; Tails]
 let inputs2 = [Tails; Head; Head]

 (0, inputs1, inputs2) |||> List.fold2 (fun acc input1 input2 ->
     match (input1, input2) with
     | Head, Head -> acc + 1
     | Tails, Tails -> acc + 1
     | _ -> acc)
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 2. Note acc is a commonly used abbreviation for "accumulator".

List.foldBack folder list state

Full Usage: List.foldBack folder list state

Parameters:
    folder : '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.

Applies a function to each element of the collection, starting from the end, threading an accumulator argument through the computation. If the input function is f and the elements are i0...iN then computes f i0 (...(f iN s)).

folder : '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.

Example

Making the sum of squares for the first 5 natural numbers

 ([1..5], 0) ||> List.foldBack (fun v acc -> acc + v * v)  // evaluates 55
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".

Example

Shopping 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 }

 let takeMore fruit (previous: BagItem list) =
     let toTakeThisTime = 
         match previous with 
         | bagItem :: otherBagItems -> bagItem.quantity + 1 
         | [] -> 1 
     { fruit = fruit; quantity = toTakeThisTime } :: previous

 let input = [ Apple; Pear; Orange ]
 
 (input, []) ||> List.foldBack takeMore
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
  [{ fruit = Apple; quantity = 3 }
   { fruit = Pear; quantity = 2 }
   { fruit = Orange; quantity = 1 }]

List.foldBack2 folder list1 list2 state

Full Usage: List.foldBack2 folder list1 list2 state

Parameters:
    folder : '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.

Applies a function to corresponding elements of two collections, threading an accumulator argument through the computation. The collections must have identical sizes. If the input function is f and the elements are i0...iN and j0...jN then computes f i0 j0 (...(f iN jN s)).

folder : '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

Count the positives, negatives and accumulate some text from back to front:
 type Count =
   { Positive: int
     Negative: int
     Text: string }

 let inputs1 = [ -1; -2; -3 ]
 let inputs2 = [ 3; 2; 1 ]
 let initialState = {Positive = 0; Negative = 0; Text = ""}

 (inputs1, inputs2, initialState) |||> List.foldBack2 (fun a b acc  ->
     let text = acc.Text + "(" + string a + "," + string b + ") "
     if a + b >= 0 then
         { acc with
             Positive = acc.Positive + 1
             Text = text }
     else
         { acc with
             Negative = acc.Negative + 1
             Text = text }
 )
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
 { Positive = 2
   Negative = 1
   Text = "(-3,1) (-2,2) (-1,3) " }
namespace Microsoft.FSharp.Text
Note acc is a commonly used abbreviation for "accumulator".

List.forall predicate list

Full Usage: List.forall predicate list

Parameters:
    predicate : 'T -> bool - The function to test the input elements.
    list : 'T list - The input list.

Returns: bool True if all of the elements satisfy the predicate.

Tests if all elements of the collection satisfy the given predicate.

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.

predicate : 'T -> bool

The function to test the input elements.

list : 'T list

The input list.

Returns: bool

True if all of the elements satisfy the predicate.

Example

 let isEven a = a % 2 = 0

 [2; 42] |> List.forall isEven // evaluates to true

 [1; 2] |> List.forall isEven // evaluates to false
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

List.forall2 predicate list1 list2

Full Usage: List.forall2 predicate list1 list2

Parameters:
    predicate : 'T1 -> 'T2 -> bool - The function to test the input elements.
    list1 : 'T1 list - The first input list.
    list2 : 'T2 list - The second input list.

Returns: bool True if all of the pairs of elements satisfy the predicate.

Tests if all corresponding elements of the collection satisfy the given predicate pairwise.

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.

predicate : 'T1 -> 'T2 -> bool

The function to test the input elements.

list1 : 'T1 list

The first input list.

list2 : 'T2 list

The second input list.

Returns: bool

True if all of the pairs of elements satisfy the predicate.

ArgumentException Thrown when the input lists differ in length.
Example

 let inputs1 = [1; 2; 3]
 let inputs2 = [1; 2; 3]

 (inputs1, inputs2) ||> List.forall2 (=)
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

 let items1 = [2017; 1; 1]
 let items2 = [2019; 19; 8]

 (items1, items2) ||> List.forall2 (=)
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

 let items1 = [1; 2; 3]
 let items2 = [1; 2]

 (items1, items2) ||> List.forall2 (=)
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.

List.groupBy projection list

Full Usage: List.groupBy projection list

Parameters:
    projection : 'T -> 'Key - A function that transforms an element of the list into a comparable key.
    list : 'T list - The input list.

Returns: ('Key * 'T list) list The result list.

Applies a key-generating function to each element of a list and yields a list of unique keys. Each unique key contains a list of all elements that match to this key.

projection : 'T -> 'Key

A function that transforms an element of the list into a comparable key.

list : 'T list

The input list.

Returns: ('Key * 'T list) list

The result list.

Example

 let inputs = [1; 2; 3; 4; 5]

 inputs |> List.groupBy (fun n -> n % 2)
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])]

List.head list

Full Usage: List.head list

Parameters:
    list : 'T list - The input list.

Returns: 'T The first element of the list.

Returns the first element of the list.

list : 'T list

The input list.

Returns: 'T

The first element of the list.

ArgumentException Thrown when the list is empty.
Example

 let inputs = ["banana"; "pear"]

 inputs |> List.head
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

 [] |> List.head
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

List.indexed list

Full Usage: List.indexed list

Parameters:
    list : 'T list - The input list.

Returns: (int * 'T) list The list of indexed elements.

Returns a new list whose elements are the corresponding elements of the input list paired with the index (from 0) of each element.

list : 'T list

The input list.

Returns: (int * 'T) list

The list of indexed elements.

Example

 let inputs = ["a"; "b"; "c"]

 inputs |> List.indexed
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")]

List.init length initializer

Full Usage: List.init length initializer

Parameters:
    length : int - The length of the list to generate.
    initializer : int -> 'T - The function to generate an element from an index.

Returns: 'T list The list of generated elements.

Creates a list by calling the given generator on each index.

length : int

The length of the list to generate.

initializer : int -> 'T

The function to generate an element from an index.

Returns: 'T list

The list of generated elements.

ArgumentException Thrown when the input length is negative.
Example

 List.init 4 (fun v -> v + 5)
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

 List.init -5 (fun v -> v + 5)
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

List.insertAt index value source

Full Usage: List.insertAt index value source

Parameters:
    index : int - The index where the item should be inserted.
    value : 'T - The value to insert.
    source : 'T list - The input list.

Returns: 'T list The result list.

Return a new list with a new item inserted before the given index.

index : int

The index where the item should be inserted.

value : 'T

The value to insert.

source : 'T list

The input list.

Returns: 'T list

The result list.

ArgumentException Thrown when index is below 0 or greater than source.Length.
Example

 let inputs = [ 0; 1; 2 ]

 inputs |> List.insertAt 1 9
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 ].

List.insertManyAt index values source

Full Usage: List.insertManyAt index values source

Parameters:
    index : int - The index where the items should be inserted.
    values : 'T seq - The values to insert.
    source : 'T list - The input list.

Returns: 'T list The result list.

Return a new list with new items inserted before the given index.

index : int

The index where the items should be inserted.

values : 'T seq

The values to insert.

source : 'T list

The input list.

Returns: 'T list

The result list.

ArgumentException Thrown when index is below 0 or greater than source.Length.
Example

 let inputs = [ 0; 1; 2 ]

 inputs |> List.insertManyAt 1 [ 8; 9 ]
 Evaluates to [ 0; 8; 9; 1; 2 ].
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

List.isEmpty list

Full Usage: List.isEmpty list

Parameters:
    list : 'T list - The input list.

Returns: bool True if the list is empty.

Returns true if the list contains no elements, false otherwise.

list : 'T list

The input list.

Returns: bool

True if the list is empty.

Example

 [ ] |> List.isEmpty
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

 [ "pear"; "banana" ] |> List.isEmpty
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

List.item index list

Full Usage: List.item index list

Parameters:
    index : int - The index to retrieve.
    list : 'T list - The input list.

Returns: 'T The value at the given index.

Indexes into the list. The first element has index 0.

index : int

The index to retrieve.

list : 'T list

The input list.

Returns: 'T

The value at the given index.

ArgumentException Thrown when the index is negative or the input list does not contain enough elements.
Example

 let inputs = [ "a"; "b"; "c" ]

 inputs |> List.item 1
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

 let inputs = [ "a"; "b"; "c" ]

 inputs |> List.item 4
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

List.iter action list

Full Usage: List.iter action list

Parameters:
    action : 'T -> unit - The function to apply to elements from the input list.
    list : 'T list - The input list.

Modifiers: inline
Type parameters: 'T

Applies the given function to each element of the collection.

action : 'T -> unit

The function to apply to elements from the input list.

list : 'T list

The input list.

Example

 let inputs = [ "a"; "b"; "c" ]

 inputs |> List.iter (printfn "%s")
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
 a
 b
 c
in the console.

List.iter2 action list1 list2

Full Usage: List.iter2 action list1 list2

Parameters:
    action : 'T1 -> 'T2 -> unit - The function to apply to pairs of elements from the input lists.
    list1 : 'T1 list - The first input list.
    list2 : 'T2 list - The second input list.

Applies the given function to two collections simultaneously. The collections must have identical sizes.

action : 'T1 -> 'T2 -> unit

The function to apply to pairs of elements from the input lists.

list1 : 'T1 list

The first input list.

list2 : 'T2 list

The second input list.

Example

 let inputs1 = [ "a"; "b"; "c" ]
 let inputs2 = [ 1; 2; 3 ]

 (inputs1, inputs2) ||> List.iter2 (printfn "%s: %i")
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
 a: 1
 b: 2
 c: 3
in the console.

List.iteri action list

Full Usage: List.iteri action list

Parameters:
    action : int -> 'T -> unit - The function to apply to the elements of the list along with their index.
    list : 'T list - The input list.

Modifiers: inline
Type parameters: 'T

Applies the given function to each element of the collection. The integer passed to the function indicates the index of the element.

action : int -> 'T -> unit

The function to apply to the elements of the list along with their index.

list : 'T list

The input list.

Example

 let inputs = [ "a"; "b"; "c" ]

 inputs |> List.iteri (fun i v -> printfn "{i}: {v}")
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
 0: a
 1: b
 2: c
in the console.

List.iteri2 action list1 list2

Full Usage: List.iteri2 action list1 list2

Parameters:
    action : int -> 'T1 -> 'T2 -> unit - The function to apply to a pair of elements from the input lists along with their index.
    list1 : 'T1 list - The first input list.
    list2 : 'T2 list - The second input list.

Applies the given function to two collections simultaneously. The collections must have identical sizes. The integer passed to the function indicates the index of the element.

action : int -> 'T1 -> 'T2 -> unit

The function to apply to a pair of elements from the input lists along with their index.

list1 : 'T1 list

The first input list.

list2 : 'T2 list

The second input list.

Example

 let inputs1 = [ "a"; "b"; "c" ]
 let inputs2 = [ "banana"; "pear"; "apple" ]

 (inputs1, inputs2) ||> List.iteri2 (fun i s1 s2 -> printfn "Index %d: %s - %s" i s1 s2)
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
 Index 0: a - banana
 Index 1: b - pear
 Index 2: c - apple
in the console.

List.last list

Full Usage: List.last list

Parameters:
    list : 'T list - The input list.

Returns: 'T The last element of the list.

Returns the last element of the list.

list : 'T list

The input list.

Returns: 'T

The last element of the list.

ArgumentException Thrown when the input does not have any elements.
Example

 [ "pear"; "banana" ] |> List.last
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

 [ ] |> List.last
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

List.length list

Full Usage: List.length list

Parameters:
    list : 'T list - The input list.

Returns: int The length of the list.

Returns the length of the list.

The notation array.Length is preferred.

list : 'T list

The input list.

Returns: int

The length of the list.

Example

 let inputs = [ "a"; "b"; "c" ]

 inputs |> List.length
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

List.map mapping list

Full Usage: List.map mapping list

Parameters:
    mapping : 'T -> 'U - The function to transform elements from the input list.
    list : 'T list - The input list.

Returns: 'U list The list of transformed elements.

Builds a new collection whose elements are the results of applying the given function to each of the elements of the collection.

mapping : 'T -> 'U

The function to transform elements from the input list.

list : 'T list

The input list.

Returns: 'U list

The list of transformed elements.

Example

 let inputs = [ "a"; "bbb"; "cc" ]

 inputs |> List.map (fun x -> x.Length)
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 ]

List.map2 mapping list1 list2

Full Usage: List.map2 mapping list1 list2

Parameters:
    mapping : 'T1 -> 'T2 -> 'U - The function to transform pairs of elements from the input lists.
    list1 : 'T1 list - The first input list.
    list2 : 'T2 list - The second input list.

Returns: 'U list The list of transformed elements.

Builds a new collection whose elements are the results of applying the given function to the corresponding elements of the two collections pairwise.

mapping : 'T1 -> 'T2 -> 'U

The function to transform pairs of elements from the input lists.

list1 : 'T1 list

The first input list.

list2 : 'T2 list

The second input list.

Returns: 'U list

The list of transformed elements.

Example

 let inputs1 = ["a"; "bad"; "good"]
 let inputs2 = [0; 2; 1]

 (inputs1, inputs2) ||> List.map2 (fun x y -> x.[y])
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']

List.map3 mapping list1 list2 list3

Full Usage: List.map3 mapping list1 list2 list3

Parameters:
    mapping : '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.

Builds a new collection whose elements are the results of applying the given function to the corresponding elements of the three collections simultaneously.

mapping : '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

 let inputs1 = [ "a"; "t"; "ti" ]
 let inputs2 = [ "l"; "h"; "m" ]
 let inputs3 = [ "l"; "e"; "e" ]

 (inputs1, inputs2, inputs3) |||> List.map3 (fun x y z -> x + y + z)
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" ]

List.mapFold mapping state list

Full Usage: List.mapFold mapping state list

Parameters:
    mapping : '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.

Combines map and fold. Builds a new list whose elements are the results of applying the given function to each of the elements of the input list. The function is also used to accumulate a final value.

mapping : '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.

Example

Accumulate the charges, and double them as well

 type Charge =
     | In of int
     | Out of int

 let inputs = [ In 1; Out 2; In 3 ]

 let newCharges, balance =
     (0, inputs) ||> List.mapFold (fun acc charge ->
         match charge with
         | In i -> In (i*2), acc + i
         | Out o -> Out (o*2), acc - o)
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".

List.mapFoldBack mapping list state

Full Usage: List.mapFoldBack mapping list state

Parameters:
    mapping : '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.

Combines map and foldBack. Builds a new list whose elements are the results of applying the given function to each of the elements of the input list. The function is also used to accumulate a final value.

mapping : '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.

Example

Accumulate the charges from back to front, and double them as well

 type Charge =
     | In of int
     | Out of int

 let charges = [ In 1; Out 2; In 3 ]

 let newCharges, balance =
     (charges, 0) ||> List.mapFoldBack (fun charge acc ->
         match charge with
         | In i -> In (i*2), acc + i
         | Out o -> Out (o*2), acc - o)
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".

List.mapi mapping list

Full Usage: List.mapi mapping list

Parameters:
    mapping : int -> 'T -> 'U - The function to transform elements and their indices.
    list : 'T list - The input list.

Returns: 'U list The list of transformed elements.

Builds a new collection whose elements are the results of applying the given function to each of the elements of the collection. The integer index passed to the function indicates the index (from 0) of the element being transformed.

mapping : int -> 'T -> 'U

The function to transform elements and their indices.

list : 'T list

The input list.

Returns: 'U list

The list of transformed elements.

Example

 let inputs = [ 10; 10; 10 ]

 inputs |> List.mapi (fun i x -> i + x)
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 ]

List.mapi2 mapping list1 list2

Full Usage: List.mapi2 mapping list1 list2

Parameters:
    mapping : 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.

Like mapi, but mapping corresponding elements from two lists of equal length.

mapping : 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

 let inputs1 = ["a"; "bad"; "good"]
 let inputs2 = [0; 2; 1]

 (inputs1, inputs2) ||> List.mapi2 (fun i x y -> i, x[y])
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')]

List.max list

Full Usage: List.max list

Parameters:
    list : 'T list - The input list.

Returns: 'T The maximum element.
Modifiers: inline
Type parameters: 'T

Return the greatest of all elements of the list, compared via Operators.max.

Raises ArgumentException if list is empty

list : 'T list

The input list.

Returns: 'T

The maximum element.

ArgumentException Thrown when the list is empty.
Example

 let inputs = [ 10; 12; 11 ]

 inputs |> List.max
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

 let inputs = [ ]

 inputs |> List.max
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.

List.maxBy projection list

Full Usage: List.maxBy projection list

Parameters:
    projection : '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

Returns the greatest of all elements of the list, compared via Operators.max on the function result.

Raises ArgumentException if list is empty.

projection : '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.

ArgumentException Thrown when the list is empty.
Example

 let inputs = ["aaa"; "b"; "cccc"]

 inputs |> List.maxBy (fun s -> s.Length)
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

 let inputs = []

 inputs |> List.maxBy (fun (s: string) -> s.Length)
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.

List.min list

Full Usage: List.min list

Parameters:
    list : 'T list - The input list.

Returns: 'T The minimum value.
Modifiers: inline
Type parameters: 'T

Returns the lowest of all elements of the list, compared via Operators.min.

Raises ArgumentException if list is empty

list : 'T list

The input list.

Returns: 'T

The minimum value.

ArgumentException Thrown when the list is empty.
Example

 let inputs = [10; 12; 11]

 inputs |> List.min
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

 let inputs = []

 inputs |> List.min
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.

List.minBy projection list

Full Usage: List.minBy projection list

Parameters:
    projection : '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

Returns the lowest of all elements of the list, compared via Operators.min on the function result

Raises ArgumentException if list is empty.

projection : '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.

ArgumentException Thrown when the list is empty.
Example

 let inputs = ["aaa"; "b"; "cccc"]

 inputs |> List.minBy (fun s -> s.Length)
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

 let inputs = []

 inputs |> List.minBy (fun (s: string) -> s.Length)
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.

List.ofArray array

Full Usage: List.ofArray array

Parameters:
    array : 'T array - The input array.

Returns: 'T list The list of elements from the array.

Builds a list from the given array.

array : 'T array

The input array.

Returns: 'T list

The list of elements from the array.

Example

 let inputs = [| 1; 2; 5 |]

 inputs |> List.ofArray
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 ].

List.ofSeq source

Full Usage: List.ofSeq source

Parameters:
    source : 'T seq - The input sequence.

Returns: 'T list The list of elements from the sequence.

Builds a new list from the given enumerable object.

source : 'T seq

The input sequence.

Returns: 'T list

The list of elements from the sequence.

Example

 let inputs = seq { 1; 2; 5 }

 inputs |> List.ofSeq
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 ].

List.pairwise list

Full Usage: List.pairwise list

Parameters:
    list : 'T list - The input list.

Returns: ('T * 'T) list The result list.

Returns a list of each element in the input list and its predecessor, with the exception of the first element which is only returned as the predecessor of the second element.

list : 'T list

The input list.

Returns: ('T * 'T) list

The result list.

Example

 let inputs = [1; 2; 3; 4]

 inputs |> List.pairwise
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)].

List.partition predicate list

Full Usage: List.partition predicate list

Parameters:
    predicate : 'T -> bool - The function to test the input elements.
    list : 'T list - The input list.

Returns: 'T list * 'T list A list containing the elements for which the predicate evaluated to true and a list containing the elements for which the predicate evaluated to false.

Splits the collection into two collections, containing the elements for which the given predicate returns True and False respectively. Element order is preserved in both of the created lists.

predicate : 'T -> bool

The function to test the input elements.

list : 'T list

The input list.

Returns: 'T list * 'T list

A list containing the elements for which the predicate evaluated to true and a list containing the elements for which the predicate evaluated to false.

Example

 let inputs = [1; 2; 3; 4]

 let evens, odds = inputs |> List.partition (fun x -> x % 2 = 0)
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].

List.permute indexMap list

Full Usage: List.permute indexMap list

Parameters:
    indexMap : int -> int - The function to map input indices to output indices.
    list : 'T list - The input list.

Returns: 'T list The permuted list.

Returns a list with all elements permuted according to the specified permutation.

indexMap : int -> int

The function to map input indices to output indices.

list : 'T list

The input list.

Returns: 'T list

The permuted list.

ArgumentException Thrown when indexMap does not produce a valid permutation.
Example

 let inputs = [1; 2; 3; 4]

 inputs |> List.permute (fun x -> (x + 1) % 4)
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].

List.pick chooser list

Full Usage: List.pick chooser list

Parameters:
    chooser : 'T -> 'U option - The function to generate options from the elements.
    list : 'T list - The input list.

Returns: 'U The first resulting value.

Applies the given function to successive elements, returning the first result where function returns Some(x) for some x. If no such element exists then raise KeyNotFoundException

chooser : 'T -> 'U option

The function to generate options from the elements.

list : 'T list

The input list.

Returns: 'U

The first resulting value.

KeyNotFoundException Thrown when the list is empty.
Example

 let input = [1; 2; 3]

 input |> List.pick (fun n -> if n % 2 = 0 then Some (string n) else None)
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

 let input = [1; 2; 3]

 input |> List.pick (fun n -> if n > 3 then Some (string n) else None)
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.

List.randomChoice source

Full Usage: List.randomChoice source

Parameters:
    source : 'T list - The input list.

Returns: 'T A randomly selected element from the input list.

Returns a random element from the given list.

source : 'T list

The input list.

Returns: 'T

A randomly selected element from the input list.

ArgumentException Thrown when the input list is empty.
Example

 let inputs = [ 0; 1; 2; 3; 4 ]

 inputs |> List.randomChoice
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 ...
Can evaluate to 3.

List.randomChoiceBy randomizer source

Full Usage: List.randomChoiceBy randomizer source

Parameters:
    randomizer : unit -> float - The randomizer function, must return a float number from [0.0..1.0) range.
    source : 'T list - The input list.

Returns: 'T A randomly selected element from the input list.

Returns a random element from the given list using the specified randomizer function.

randomizer : unit -> float

The randomizer function, must return a float number from [0.0..1.0) range.

source : 'T list

The input list.

Returns: 'T

A randomly selected element from the input list.

ArgumentException Thrown when the input list is empty.
ArgumentOutOfRangeException Thrown when the randomizer function returns a value outside the range [0, 1).
Example

 let inputs = [ 0; 1; 2; 3; 4 ]

 inputs |> List.randomChoiceBy Random.Shared.NextDouble
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 ...
Can evaluate to 3.

List.randomChoiceWith random source

Full Usage: List.randomChoiceWith random source

Parameters:
    random : Random - The Random instance.
    source : 'T list - The input list.

Returns: 'T A randomly selected element from the input list.

Returns a random element from the given list with the specified Random instance, each element can be selected multiple times.

random : Random

The Random instance.

source : 'T list

The input list.

Returns: 'T

A randomly selected element from the input list.

ArgumentNullException Thrown when the random argument is null.
ArgumentException Thrown when the input list is empty.
Example

 let inputs = [ 0; 1; 2; 3; 4 ]

 inputs |> List.randomChoiceWith Random.Shared
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 ...
Can evaluate to 3.

List.randomChoices count source

Full Usage: List.randomChoices count source

Parameters:
    count : int - The number of elements to return.
    source : 'T list - The input list.

Returns: 'T list A list of randomly selected elements from the input list.

Returns a list of random elements from the given list.

count : int

The number of elements to return.

source : 'T list

The input list.

Returns: 'T list

A list of randomly selected elements from the input list.

ArgumentException Thrown when the input list is empty.
ArgumentException Thrown when count is less than 0.
Example

 let inputs = [ 0; 1; 2; 3; 4 ]

 inputs |> List.randomChoices 3
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 ...
Can evaluate to [ 3; 1; 3 ].

List.randomChoicesBy randomizer count source

Full Usage: List.randomChoicesBy randomizer count source

Parameters:
    randomizer : unit -> float - The randomizer function, must return a float number from [0.0..1.0) range.
    count : int - The number of elements to return.
    source : 'T list - The input list.

Returns: 'T list A list of randomly selected elements from the input list.

Returns a list of random elements from the given list using the specified randomizer function.

randomizer : unit -> float

The randomizer function, must return a float number from [0.0..1.0) range.

count : int

The number of elements to return.

source : 'T list

The input list.

Returns: 'T list

A list of randomly selected elements from the input list.

ArgumentException Thrown when the input list is empty.
ArgumentException Thrown when count is less than 0.
ArgumentOutOfRangeException Thrown when the randomizer function returns a value outside the range [0, 1).
Example

 let inputs = [ 0; 1; 2; 3; 4 ]

 inputs |> List.randomChoicesBy Random.Shared.NextDouble 3
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 ...
Can evaluate to [ 3; 1; 3 ].

List.randomChoicesWith random count source

Full Usage: List.randomChoicesWith random count source

Parameters:
    random : Random - The Random instance.
    count : int - The number of elements to return.
    source : 'T list - The input list.

Returns: 'T list A list of randomly selected elements from the input list.

Returns a list of random elements from the given list with the specified Random instance, each element can be selected multiple times.

random : Random

The Random instance.

count : int

The number of elements to return.

source : 'T list

The input list.

Returns: 'T list

A list of randomly selected elements from the input list.

ArgumentNullException Thrown when the random argument is null.
ArgumentException Thrown when the input list is empty.
ArgumentException Thrown when count is less than 0.
Example

 let inputs = [ 0; 1; 2; 3; 4 ]

 inputs |> Array.randomChoicesWith Random.Shared 3
val inputs: int list
module Array from Microsoft.FSharp.Collections
Can evaluate to [ 3; 1; 3 ].

List.randomSample count source

Full Usage: List.randomSample count source

Parameters:
    count : int - The number of elements to return.
    source : 'T list - The input list.

Returns: 'T list A list of randomly selected elements from the input list.

Returns a random sample of elements from the given list, each element can be selected only once.

count : int

The number of elements to return.

source : 'T list

The input list.

Returns: 'T list

A list of randomly selected elements from the input list.

ArgumentException Thrown when the input list is empty.
ArgumentException Thrown when count is less than 0.
ArgumentException Thrown when count is greater than the length of the input list.
Example

 let inputs = [ 0; 1; 2; 3; 4 ]

 inputs |> List.randomSample 3
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 ...
Can evaluate to [ 3; 1; 2 ].

List.randomSampleBy randomizer count source

Full Usage: List.randomSampleBy randomizer count source

Parameters:
    randomizer : unit -> float - The randomizer function, must return a float number from [0.0..1.0) range.
    count : int - The number of elements to return.
    source : 'T list - The input list.

Returns: 'T list A list of randomly selected elements from the input list.

Returns a random sample of elements from the given list using the specified randomizer function, each element can be selected only once.

randomizer : unit -> float

The randomizer function, must return a float number from [0.0..1.0) range.

count : int

The number of elements to return.

source : 'T list

The input list.

Returns: 'T list

A list of randomly selected elements from the input list.

ArgumentException Thrown when the input list is empty.
ArgumentException Thrown when count is less than 0.
ArgumentException Thrown when count is greater than the length of the input list.
ArgumentOutOfRangeException Thrown when the randomizer function returns a value outside the range [0, 1).
Example

 let inputs = [ 0; 1; 2; 3; 4 ]

 inputs |> List.randomSampleBy Random.Shared.NextDouble 3
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 ...
Can evaluate to [ 3; 1; 2 ].

List.randomSampleWith random count source

Full Usage: List.randomSampleWith random count source

Parameters:
    random : Random - The Random instance.
    count : int - The number of elements to return.
    source : 'T list - The input list.

Returns: 'T list A list of randomly selected elements from the input list.

Returns a random sample of elements from the given list with the specified Random instance, each element can be selected only once.

random : Random

The Random instance.

count : int

The number of elements to return.

source : 'T list

The input list.

Returns: 'T list

A list of randomly selected elements from the input list.

ArgumentNullException Thrown when the random argument is null.
ArgumentException Thrown when the input list is empty.
ArgumentException Thrown when count is less than 0.
ArgumentException Thrown when count is greater than the length of the input list.
Example

 let inputs = [ 0; 1; 2; 3; 4 ]

 inputs |> List.randomSampleWith Random.Shared 3
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 ...
Can evaluate to [ 3; 1; 2 ].

List.randomShuffle source

Full Usage: List.randomShuffle source

Parameters:
    source : 'T list - The input list.

Returns: 'T list The result list.

Return a new list shuffled in a random order.

source : 'T list

The input list.

Returns: 'T list

The result list.

Example

 let inputs = [ 0; 1; 2; 3; 4 ]

 inputs |> List.randomShuffle
 Can evaluate to [ 0; 2; 4; 3; 1 ].
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 ...

List.randomShuffleBy randomizer source

Full Usage: List.randomShuffleBy randomizer source

Parameters:
    randomizer : unit -> float - The randomizer function, must return a float number from [0.0..1.0) range.
    source : 'T list - The input list.

Returns: 'T list The result list.

Return a new list shuffled in a random order using the specified randomizer function.

randomizer : unit -> float

The randomizer function, must return a float number from [0.0..1.0) range.

source : 'T list

The input list.

Returns: 'T list

The result list.

ArgumentOutOfRangeException Thrown when the randomizer function returns a value outside the range [0, 1).
Example

 let inputs = [ 0; 1; 2; 3; 4 ]

 inputs |> List.randomShuffleBy Random.Shared.NextDouble
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 ...
Can evaluate to [ 0; 2; 4; 3; 1 ].

List.randomShuffleWith random source

Full Usage: List.randomShuffleWith random source

Parameters:
    random : Random - The Random instance.
    source : 'T list - The input list.

Returns: 'T list The result list.

Return a new list shuffled in a random order with the specified Random instance.

random : Random

The Random instance.

source : 'T list

The input list.

Returns: 'T list

The result list.

ArgumentNullException Thrown when the random argument is null.
Example

 let inputs = [ 0; 1; 2; 3; 4 ]

 inputs |> List.randomShuffleWith Random.Shared
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 ...
Can evaluate to [ 0; 2; 4; 3; 1 ].

List.reduce reduction list

Full Usage: List.reduce reduction list

Parameters:
    reduction : '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 f and the elements are i0...iN then computes f (... (f i0 i1) i2 ...) iN.

Raises ArgumentException if list is empty

reduction : '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.

ArgumentException Thrown when the list is empty.
Example

 let inputs = [1; 3; 4; 2]

 inputs |> List.reduce (fun a b -> a * 10 + b)
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

List.reduceBack reduction list

Full Usage: List.reduceBack reduction list

Parameters:
    reduction : '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.

Applies a function to each element of the collection, starting from the end, threading an accumulator argument through the computation. If the input function is f and the elements are i0...iN then computes f i0 (...(f iN-1 iN)).

reduction : '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.

ArgumentException Thrown when the list is empty.
Example

 let inputs = [1; 3; 4; 2]

 inputs |> List.reduceBack (fun a b -> a + b * 10)
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

List.removeAt index source

Full Usage: List.removeAt index source

Parameters:
    index : int - The index of the item to be removed.
    source : 'T list - The input list.

Returns: 'T list The result list.

Return a new list with the item at a given index removed.

index : int

The index of the item to be removed.

source : 'T list

The input list.

Returns: 'T list

The result list.

ArgumentException Thrown when index is outside 0..source.Length - 1
Example

 let inputs = [ 0; 1; 2 ]

 inputs |> List.removeAt 1
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 ]

List.removeManyAt index count source

Full Usage: List.removeManyAt index count source

Parameters:
    index : int - The index of the item to be removed.
    count : int - The number of items to remove.
    source : 'T list - The input list.

Returns: 'T list The result list.

Return a new list with the number of items starting at a given index removed.

index : int

The index of the item to be removed.

count : int

The number of items to remove.

source : 'T list

The input list.

Returns: 'T list

The result list.

ArgumentException Thrown when index is outside 0..source.Length - count
Example

 let inputs = [ 0; 1; 2; 3 ]

 inputs |> List.removeManyAt 1 2
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 ].

List.replicate count initial

Full Usage: List.replicate count initial

Parameters:
    count : int - The number of elements to replicate.
    initial : 'T - The value to replicate

Returns: 'T list The generated list.

Creates a list by replicating the given initial value.

count : int

The number of elements to replicate.

initial : 'T

The value to replicate

Returns: 'T list

The generated list.

Example

 List.replicate 3 "a"
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" ].

List.rev list

Full Usage: List.rev list

Parameters:
    list : 'T list - The input list.

Returns: 'T list The reversed list.

Returns a new list with the elements in reverse order.

list : 'T list

The input list.

Returns: 'T list

The reversed list.

Example

 let inputs = [ 0; 1; 2 ]

 inputs |> List.rev
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 ].

List.scan folder state list

Full Usage: List.scan folder state list

Parameters:
    folder : '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 list The list of states.

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.

folder : '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 list

The list of states.

Example

Apply a list charges and collect the running balances as each is applied:

 type Charge =
     | In of int
     | Out of int

 let inputs = [In 1; Out 2; In 3]

 (0, inputs) ||> List.scan (fun acc charge ->
     match charge with
     | In i -> acc + i
     | Out o -> acc - o)
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".

List.scanBack folder list state

Full Usage: List.scanBack folder list state

Parameters:
    folder : '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 list The list of states.

Like foldBack, but returns both the intermediary and final results

folder : '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 list

The list of states.

Example

Apply a list charges from back to front, and collect the running balances as each is applied:

 type Charge =
     | In of int
     | Out of int

 let inputs = [ In 1; Out 2; In 3 ]

 (inputs, 0) ||> List.scanBack (fun charge acc ->
     match charge with
     | In i -> acc + i
     | Out o -> acc - o)
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".

List.singleton value

Full Usage: List.singleton value

Parameters:
    value : 'T - The input item.

Returns: 'T list The result list of one item.
Modifiers: inline
Type parameters: 'T

Returns a list that contains one item only.

value : 'T

The input item.

Returns: 'T list

The result list of one item.

Example

 List.singleton 7
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 ].

List.skip count list

Full Usage: List.skip count list

Parameters:
    count : int - The number of elements to skip. If the number is 0 or negative the input list is returned.
    list : 'T list - The input list.

Returns: 'T list The list after removing the first N elements.

Returns the list after removing the first N elements.

count : int

The number of elements to skip. If the number is 0 or negative the input list is returned.

list : 'T list

The input list.

Returns: 'T list

The list after removing the first N elements.

ArgumentException Thrown when count exceeds the number of elements in the list.
Example

 let inputs = ["a"; "b"; "c"; "d"]

 inputs |> List.skip 2
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

 let inputs = ["a"; "b"; "c"; "d"]

 inputs |> List.skip 5
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

 let inputs = ["a"; "b"; "c"; "d"]

 inputs |> List.skip -1
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"].

List.skipWhile predicate list

Full Usage: List.skipWhile predicate list

Parameters:
    predicate : 'T -> bool - A function that evaluates an element of the list to a boolean value.
    list : 'T list - The input list.

Returns: 'T list The result list.

Bypasses elements in a list while the given predicate returns True, and then returns the remaining elements of the list.

predicate : 'T -> bool

A function that evaluates an element of the list to a boolean value.

list : 'T list

The input list.

Returns: 'T list

The result list.

Example

 let inputs = ["a"; "bbb"; "cc"; "d"]

 inputs |> List.skipWhile (fun x -> x.Length < 3)
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"]

List.sort list

Full Usage: List.sort list

Parameters:
    list : 'T list - The input list.

Returns: 'T list The sorted list.

Sorts the given list using Operators.compare.

This is a stable sort, i.e. the original order of equal elements is preserved.

list : 'T list

The input list.

Returns: 'T list

The sorted list.

Example

 let input = [8; 4; 3; 1; 6; 1]

 List.sort input
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].

List.sortBy projection list

Full Usage: List.sortBy projection list

Parameters:
    projection : 'T -> 'Key - The function to transform the list elements into the type to be compared.
    list : 'T list - The input list.

Returns: 'T list The sorted list.

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.

projection : 'T -> 'Key

The function to transform the list elements into the type to be compared.

list : 'T list

The input list.

Returns: 'T list

The sorted list.

Example

 let input = [ "a"; "bbb"; "cccc"; "dd" ]

 input |> List.sortBy (fun s -> s.Length)
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"].

List.sortByDescending projection list

Full Usage: List.sortByDescending projection list

Parameters:
    projection : 'T -> 'Key - The function to transform the list elements into the type to be compared.
    list : 'T list - The input list.

Returns: 'T list The sorted list.
Modifiers: inline
Type parameters: 'T, 'Key

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.

projection : 'T -> 'Key

The function to transform the list elements into the type to be compared.

list : 'T list

The input list.

Returns: 'T list

The sorted list.

Example

 let input = ["a"; "bbb"; "cccc"; "dd"]

 input |> List.sortByDescending (fun s -> s.Length)
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"].

List.sortDescending list

Full Usage: List.sortDescending list

Parameters:
    list : 'T list - The input list.

Returns: 'T list The sorted list.
Modifiers: inline
Type parameters: 'T

Sorts the given list in descending order using Operators.compare.

This is a stable sort, i.e. the original order of equal elements is preserved.

list : 'T list

The input list.

Returns: 'T list

The sorted list.

Example

 let input = [8; 4; 3; 1; 6; 1]

 input |> List.sortDescending
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].

List.sortWith comparer list

Full Usage: List.sortWith comparer list

Parameters:
    comparer : 'T -> 'T -> int - The function to compare the list elements.
    list : 'T list - The input list.

Returns: 'T list The sorted list.

Sorts the given list using the given comparison function.

This is a stable sort, i.e. the original order of equal elements is preserved.

comparer : 'T -> 'T -> int

The function to compare the list elements.

list : 'T list

The input list.

Returns: 'T list

The sorted list.

Example

Sort a list of pairs using a comparison function that compares string lengths then index numbers:

 let compareEntries (n1: int, s1: string) (n2: int, s2: string) =
     let c = compare s1.Length s2.Length
     if c <> 0 then c else
     compare n1 n2

 let input = [ (0,"aa"); (1,"bbb"); (2,"cc"); (3,"dd") ]

 input |> List.sortWith compareEntries
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")].

List.splitAt index list

Full Usage: List.splitAt index list

Parameters:
    index : int - The index at which the list is split.
    list : 'T list - The input list.

Returns: 'T list * 'T list The two split lists.

Splits a list into two lists, at the given index.

index : int

The index at which the list is split.

list : 'T list

The input list.

Returns: 'T list * 'T list

The two split lists.

InvalidOperationException Thrown when split index exceeds the number of elements in the list.
Example

 let input = [8; 4; 3; 1; 6; 1]

 let front, back = input |> List.splitAt 3
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].

List.splitInto count list

Full Usage: List.splitInto count list

Parameters:
    count : int - The maximum number of chunks.
    list : 'T list - The input list.

Returns: 'T list list The list split into chunks.

Splits the input list into at most count chunks.

count : int

The maximum number of chunks.

list : 'T list

The input list.

Returns: 'T list list

The list split into chunks.

ArgumentException Thrown when count is not positive.
Example

 [1..10] |> List.splitInto 2
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

 [1..10] |> List.splitInto 4
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]].

List.sum list

Full Usage: List.sum list

Parameters:
    list : ^T list - The input list.

Returns: ^T The resulting sum.
Modifiers: inline
Type parameters: ^T

Returns the sum of the elements in the list.

list : ^T list

The input list.

Returns: ^T

The resulting sum.

Example

 let input = [ 1; 5; 3; 2 ]

 input |> List.sum
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.

List.sumBy projection list

Full Usage: List.sumBy projection list

Parameters:
    projection : '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

Returns the sum of the results generated by applying the function to each element of the list.

projection : '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.

Example

 let input = [ "aa"; "bbb"; "cc" ]

 input |> List.sumBy (fun s -> s.Length)
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.

List.tail list

Full Usage: List.tail list

Parameters:
    list : 'T list - The input list.

Returns: 'T list The list after removing the first element.

Returns the list after removing the first element.

list : 'T list

The input list.

Returns: 'T list

The list after removing the first element.

ArgumentException Thrown when the list is empty.
Example

 let inputs = ["a"; "bb"; "ccc"]

 inputs |> List.tail
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"]

List.take count list

Full Usage: List.take count list

Parameters:
    count : int - The number of items to take.
    list : 'T list - The input list.

Returns: 'T list The result list.

Returns the first N elements of the list.

Throws InvalidOperationException if the count exceeds the number of elements in the list. List.truncate returns as many items as the list contains instead of throwing an exception.

count : int

The number of items to take.

list : 'T list

The input list.

Returns: 'T list

The result list.

ArgumentException Thrown when the input list is empty.
InvalidOperationException Thrown when count exceeds the number of elements in the list.
Example

 let inputs = ["a"; "b"; "c"; "d"]

 inputs |> List.take 2
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

 let inputs = ["a"; "b"; "c"; "d"]

 inputs |> List.take 6
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

 let inputs = ["a"; "b"; "c"; "d"]

 inputs |> List.take 0
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.

List.takeWhile predicate list

Full Usage: List.takeWhile predicate list

Parameters:
    predicate : 'T -> bool - A function that evaluates to false when no more items should be returned.
    list : 'T list - The input list.

Returns: 'T list The result list.

Returns a list that contains all elements of the original list while the given predicate returns True, and then returns no further elements.

predicate : 'T -> bool

A function that evaluates to false when no more items should be returned.

list : 'T list

The input list.

Returns: 'T list

The result list.

Example

 let inputs = ["a"; "bb"; "ccc"; "d"]

 inputs |> List.takeWhile (fun x -> x.Length < 3)
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"]

List.toArray list

Full Usage: List.toArray list

Parameters:
    list : 'T list - The input list.

Returns: 'T array The array containing the elements of the list.

Builds an array from the given list.

list : 'T list

The input list.

Returns: 'T array

The array containing the elements of the list.

Example

 let inputs = [ 1; 2; 5 ]

 inputs |> List.toArray
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 |].

List.toSeq list

Full Usage: List.toSeq list

Parameters:
    list : 'T list - The input list.

Returns: 'T seq The sequence of elements in the list.

Views the given list as a sequence.

list : 'T list

The input list.

Returns: 'T seq

The sequence of elements in the list.

Example

 let inputs = [ 1; 2; 5 ]

 inputs |> List.toSeq
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 }.

List.transpose lists

Full Usage: List.transpose lists

Parameters:
    lists : 'T list seq - The input sequence of list.

Returns: 'T list list The transposed list.

Returns the transpose of the given sequence of lists.

lists : 'T list seq

The input sequence of list.

Returns: 'T list list

The transposed list.

ArgumentNullException Thrown when the input sequence is null.
ArgumentException Thrown when the input lists differ in length.
Example

 let inputs =
     [ [ 10; 20; 30 ]
       [ 11; 21; 31 ] ]

 inputs |> List.transpose
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] ].

List.truncate count list

Full Usage: List.truncate count list

Parameters:
    count : int - The maximum number of items to return.
    list : 'T list - The input list.

Returns: 'T list The result list.

Returns at most N elements in a new list.

count : int

The maximum number of items to return.

list : 'T list

The input list.

Returns: 'T list

The result list.

Example

 let inputs = ["a"; "b"; "c"; "d"]

 inputs |> List.truncate 2
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

 let inputs = ["a"; "b"; "c"; "d"]

 inputs |> List.truncate 6
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

 let inputs = ["a"; "b"; "c"; "d"]

 inputs |> List.truncate 0
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.

List.tryExactlyOne list

Full Usage: List.tryExactlyOne list

Parameters:
    list : 'T list - The input list.

Returns: 'T option The only element of the list or None.

Returns the only element of the list or None if it is empty or contains more than one element.

list : 'T list

The input list.

Returns: 'T option

The only element of the list or None.

Example

 [1] |> List.tryExactlyOne               // evaluates Some 1
 [1;2] |> List.tryExactlyOne             // evaluates None
 ([] : int list) |> List.tryExactlyOne   // evaluates None
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>

List.tryFind predicate list

Full Usage: List.tryFind predicate list

Parameters:
    predicate : 'T -> bool - The function to test the input elements.
    list : 'T list - The input list.

Returns: 'T option The first element for which the predicate returns true, or None if every element evaluates to false.

Returns the first element for which the given function returns True. Return None if no such element exists.

predicate : 'T -> bool

The function to test the input elements.

list : 'T list

The input list.

Returns: 'T option

The first element for which the predicate returns true, or None if every element evaluates to false.

Example

Try to find the first even number:

 let inputs = [1; 2; 3]

 inputs |> List.tryFind (fun elm -> elm % 2 = 0)
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

Example

Try to find the first even number:

 let inputs = [1; 5; 3]

 inputs |> List.tryFind (fun elm -> elm % 2 = 0)
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

List.tryFindBack predicate list

Full Usage: List.tryFindBack predicate list

Parameters:
    predicate : 'T -> bool - The function to test the input elements.
    list : 'T list - The input list.

Returns: 'T option The last element for which the predicate returns true, or None if every element evaluates to false.

Returns the last element for which the given function returns True. Return None if no such element exists.

predicate : 'T -> bool

The function to test the input elements.

list : 'T list

The input list.

Returns: 'T option

The last element for which the predicate returns true, or None if every element evaluates to false.

Example

Try to find the first even number from the back:

 let inputs = [1; 2; 3; 4; 5]

 inputs |> List.tryFindBack (fun elm -> elm % 2 = 0)
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

Example

Try to find the first even number from the back:

 let inputs = [1; 5; 3]

 inputs |> List.tryFindBack (fun elm -> elm % 2 = 0)
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

List.tryFindIndex predicate list

Full Usage: List.tryFindIndex predicate list

Parameters:
    predicate : 'T -> bool - The function to test the input elements.
    list : 'T list - The input list.

Returns: int option The index of the first element for which the predicate returns true, or None if every element evaluates to false.

Returns the index of the first element in the list that satisfies the given predicate. Return None if no such element exists.

predicate : 'T -> bool

The function to test the input elements.

list : 'T list

The input list.

Returns: int option

The index of the first element for which the predicate returns true, or None if every element evaluates to false.

Example

Try to find the index of the first even number:

 let inputs = [1; 2; 3; 4; 5]

 inputs |> List.tryFindIndex (fun elm -> elm % 2 = 0)
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

Example

Try to find the index of the first even number:

 let inputs = [1; 3; 5; 7]

 inputs |> List.tryFindIndex (fun elm -> elm % 2 = 0)
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

List.tryFindIndexBack predicate list

Full Usage: List.tryFindIndexBack predicate list

Parameters:
    predicate : 'T -> bool - The function to test the input elements.
    list : 'T list - The input list.

Returns: int option The index of the last element for which the predicate returns true, or None if every element evaluates to false.

Returns the index of the last element in the list that satisfies the given predicate. Return None if no such element exists.

predicate : 'T -> bool

The function to test the input elements.

list : 'T list

The input list.

Returns: int option

The index of the last element for which the predicate returns true, or None if every element evaluates to false.

Example

Try to find the index of the first even number from the back:

 let inputs = [1; 2; 3; 4; 5]

 inputs |> List.tryFindIndexBack (fun elm -> elm % 2 = 0)
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

Example

Try to find the index of the first even number from the back:

 let inputs = [1; 3; 5; 7]

 inputs |> List.tryFindIndexBack (fun elm -> elm % 2 = 0)
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

List.tryHead list

Full Usage: List.tryHead list

Parameters:
    list : 'T list - The input list.

Returns: 'T option The first element of the list or None.

Returns the first element of the list, or None if the list is empty.

list : 'T list

The input list.

Returns: 'T option

The first element of the list or None.

Example

 let inputs = [ "banana"; "pear" ]

 inputs |> List.tryHead
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

 let inputs : int list = []

 inputs |> List.tryHead
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

List.tryItem index list

Full Usage: List.tryItem index list

Parameters:
    index : int - The index to retrieve.
    list : 'T list - The input list.

Returns: 'T option The value at the given index or None.

Tries to find the nth element in the list. Returns None if index is negative or the list does not contain enough elements.

index : int

The index to retrieve.

list : 'T list

The input list.

Returns: 'T option

The value at the given index or None.

Example

 let inputs = ["a"; "b"; "c"]

 inputs |> List.tryItem 1
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

 let inputs = ["a"; "b"; "c"]

 inputs |> List.tryItem 4
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.

List.tryLast list

Full Usage: List.tryLast list

Parameters:
    list : 'T list - The input list.

Returns: 'T option The last element of the list or None.

Returns the last element of the list. Return None if no such element exists.

list : 'T list

The input list.

Returns: 'T option

The last element of the list or None.

Example

 [ "pear"; "banana" ] |> List.tryLast
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

 [ ] |> List.tryLast
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

List.tryPick chooser list

Full Usage: List.tryPick chooser list

Parameters:
    chooser : 'T -> 'U option - The function to generate options from the elements.
    list : 'T list - The input list.

Returns: 'U option The first resulting value or None.

Applies the given function to successive elements, returning Some(x) the first result where function returns Some(x) for some x. If no such element exists then return None.

chooser : 'T -> 'U option

The function to generate options from the elements.

list : 'T list

The input list.

Returns: 'U option

The first resulting value or None.

Example

 let input = [1; 2; 3]

 input |> List.tryPick (fun n -> if n % 2 = 0 then Some (string n) else None)
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

 let input = [1; 2; 3]

 input |> List.tryPick (fun n -> if n > 3 then Some (string n) else None)
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.

List.unfold generator state

Full Usage: List.unfold generator state

Parameters:
    generator : '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.

Returns a list that contains the elements generated by the given computation. The generator is repeatedly called to build the list until it returns None. The given initial state argument is passed to the element generator.

generator : '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

 1 |> List.unfold (fun state -> if state > 100 then None else Some (state, state * 2))
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]

List.unzip list

Full Usage: List.unzip list

Parameters:
    list : ('T1 * 'T2) list - The input list.

Returns: 'T1 list * 'T2 list Two lists of split elements.

Splits a list of pairs into two lists.

list : ('T1 * 'T2) list

The input list.

Returns: 'T1 list * 'T2 list

Two lists of split elements.

Example

 let inputs = [(1, "one"); (2, "two")]

 let numbers, names = inputs |> List.unzip
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"].

List.unzip3 list

Full Usage: List.unzip3 list

Parameters:
    list : ('T1 * 'T2 * 'T3) list - The input list.

Returns: 'T1 list * 'T2 list * 'T3 list Three lists of split elements.

Splits a list of triples into three lists.

list : ('T1 * 'T2 * 'T3) list

The input list.

Returns: 'T1 list * 'T2 list * 'T3 list

Three lists of split elements.

Example

 let inputs = [(1, "one", "I"); (2, "two", "II")]

 let numbers, names, roman = inputs |> List.unzip3
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"].

List.updateAt index value source

Full Usage: List.updateAt index value source

Parameters:
    index : int - The index of the item to be replaced.
    value : 'T - The new value.
    source : 'T list - The input list.

Returns: 'T list The result list.

Return a new list with the item at a given index set to the new value.

index : int

The index of the item to be replaced.

value : 'T

The new value.

source : 'T list

The input list.

Returns: 'T list

The result list.

ArgumentException Thrown when index is outside 0..source.Length - 1
Example

 let inputs = [ 0; 1; 2 ]

 inputs |> List.updateAt 1 9
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 ].

List.where predicate list

Full Usage: List.where predicate list

Parameters:
    predicate : 'T -> bool - The function to test the input elements.
    list : 'T list - The input list.

Returns: 'T list A list containing only the elements that satisfy the predicate.

Returns a new list containing only the elements of the list for which the given predicate returns "true"

This is identical to List.filter.

predicate : 'T -> bool

The function to test the input elements.

list : 'T list

The input list.

Returns: 'T list

A list containing only the elements that satisfy the predicate.

Example

Select only the even numbers:

 let inputs = [1; 2; 3; 4]

 inputs |> List.where (fun elm -> elm % 2 = 0)
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]

List.windowed windowSize list

Full Usage: List.windowed windowSize list

Parameters:
    windowSize : int - The number of elements in each window.
    list : 'T list - The input list.

Returns: 'T list list The result list.

Returns a list of sliding windows containing elements drawn from the input list. Each window is returned as a fresh list.

windowSize : int

The number of elements in each window.

list : 'T list

The input list.

Returns: 'T list list

The result list.

ArgumentException Thrown when windowSize is not positive.
Example

 let inputs = [1; 2; 3; 4; 5]

 inputs |> List.windowed 3
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]]

List.zip list1 list2

Full Usage: List.zip list1 list2

Parameters:
    list1 : 'T1 list - The first input list.
    list2 : 'T2 list - The second input list.

Returns: ('T1 * 'T2) list A single list containing pairs of matching elements from the input lists.

Combines the two lists into a list of pairs. The two lists must have equal lengths.

list1 : 'T1 list

The first input list.

list2 : 'T2 list

The second input list.

Returns: ('T1 * 'T2) list

A single list containing pairs of matching elements from the input lists.

Example

 let numbers = [1; 2]
 let names = ["one"; "two"]

 List.zip numbers names
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")].

List.zip3 list1 list2 list3

Full Usage: List.zip3 list1 list2 list3

Parameters:
    list1 : 'T1 list - The first input list.
    list2 : 'T2 list - The second input list.
    list3 : 'T3 list - The third input list.

Returns: ('T1 * 'T2 * 'T3) list A single list containing triples of matching elements from the input lists.

Combines the three lists into a list of triples. The lists must have equal lengths.

list1 : 'T1 list

The first input list.

list2 : 'T2 list

The second input list.

list3 : 'T3 list

The third input list.

Returns: ('T1 * 'T2 * 'T3) list

A single list containing triples of matching elements from the input lists.

Example

 let numbers = [1; 2]
 let names = ["one"; "two"]
 let roman = ["I"; "II"]

 List.zip3 numbers names roman
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")].

Type something to start searching.