A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://fsharp.github.io/fsharp-core-docs/reference/fsharp-collections-listmodule.html below:

List (FSharp.Core) | FSharp.Core

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.

 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") ]

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.

 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 ]

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

list : ^T list

The input list.

Returns: ^T

The resulting average.

 [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

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.

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

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).

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 ]
 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" ]
 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

 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

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

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.

 [ 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 ] ]
 [ 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 ] ]

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.

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)

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.

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

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.

 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

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.

 [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.
 [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.
 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.
 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.

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.

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)]

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.

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

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.

 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)

Returns an empty list of the given type.

Returns: 'T list

Returns the only element of the list.

list : 'T list

The input list.

Returns: 'T

The only element of the list.

 ["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

 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
 [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

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.

 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")].
 [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)

 [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)

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

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.

 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

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

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.

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

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.

 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")]

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.

 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

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.

 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

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.
 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

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.
 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

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.

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

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

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.

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".

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.

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".

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

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.

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".

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

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.

 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

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

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.

 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.
 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.
 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.

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.

 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])]

Returns the first element of the list.

list : 'T list

The input list.

Returns: 'T

The first element of the list.

 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
 [] |> 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

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.

 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")]

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.

 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]
 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

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.

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

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.

 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

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

list : 'T list

The input list.

Returns: bool

True if the list is empty.

 [ ] |> 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
 [ "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

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.
 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"
 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

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.

 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.

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.

 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.

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.

 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.

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.

 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.

Returns the last element of the list.

list : 'T list

The input list.

Returns: 'T

The last element of the list.

 [ "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
 [ ] |> 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

Returns the length of the list.

list : 'T list

The input list.

Returns: int

The length of the list.

 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

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.

 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 ]

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.

 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']

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.

 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" ]

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.

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".

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.

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".

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.

 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 ]

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.

 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')]

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

list : 'T list

The input list.

Returns: 'T

The maximum element.

 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
 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.

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

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.

 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"
 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.

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

list : 'T list

The input list.

Returns: 'T

The minimum value.

 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
 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.

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

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.

 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"
 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.

Builds a list from the given array.

array : 'T array

The input array.

Returns: 'T list

The list of elements from the array.

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

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.

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

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

list : 'T list

The input list.

Returns: ('T * 'T) list

The result list.

 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)].

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.

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

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.

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

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.

 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".
 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.

Returns a random element from the given list.

source : 'T list

The input list.

Returns: 'T

A randomly selected element from the input list.

 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.

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.

 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.

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.

 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.

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.

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

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.

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

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.

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

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.

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

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.

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

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.

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

Return a new list shuffled in a random order.

source : 'T list

The input list.

Returns: 'T list

The result list.

 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 ...

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.

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

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.

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

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.

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.

 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

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.

 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

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.

 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 ]

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.

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

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.

 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" ].

Returns a new list with the elements in reverse order.

list : 'T list

The input list.

Returns: 'T list

The reversed list.

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

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.

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".

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.

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".

Returns a list that contains one item only.

value : 'T

The input item.

Returns: 'T list

The result list of one item.

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

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.

 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"]
 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.
 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"].

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.

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

The input list.

Returns: 'T list

The sorted list.

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

Sorts the given list using keys given by the given projection. Keys are compared using Operators.compare.

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.

 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"].

Sorts the given list in descending order using keys given by the given projection. Keys are compared using Operators.compare.

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.

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

The input list.

Returns: 'T list

The sorted list.

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

Sorts the given list using the given comparison function.

comparer : 'T -> 'T -> int

The function to compare the list elements.

list : 'T list

The input list.

Returns: 'T list

The sorted list.

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

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.

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

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.

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

Returns the sum of the elements in the list.

list : ^T list

The input list.

Returns: ^T

The resulting sum.

 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.

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.

 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.

Returns the list after removing the first element.

list : 'T list

The input list.

Returns: 'T list

The list after removing the first element.

 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"]

Returns the first N elements of the list.

count : int

The number of items to take.

list : 'T list

The input list.

Returns: 'T list

The result list.

 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"]
 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.
 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.

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.

 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"]

Builds an array from the given list.

list : 'T list

The input list.

Returns: 'T array

The array containing the elements of the list.

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

Views the given list as a sequence.

list : 'T list

The input list.

Returns: 'T seq

The sequence of elements in the list.

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

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.

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

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.

 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"]
 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"]
 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.

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.

 [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>

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.

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

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

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.

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

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

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.

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

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

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.

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

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

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.

 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"
 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

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.

 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".
 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.

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.

 [ "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"
 [ ] |> 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

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.

 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".
 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.

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.

 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]

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.

 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"].

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.

 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"].

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.

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

Returns a new list containing only the elements of the list 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.

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]

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.

 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]]

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.

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

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.

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

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4