FSharpPlus


List Module

Additional operations on List

Functions and values

Function or value Description

List.apply f x

Full Usage: List.apply f x

Parameters:
    f : ('T -> 'U) list - The list of functions.
    x : 'T list - The list of values.

Returns: 'U list A concatenated list of the result lists of applying each function to each value

Applies a list of functions to a list of values and concatenates them

f : ('T -> 'U) list

The list of functions.

x : 'T list

The list of values.

Returns: 'U list

A concatenated list of the result lists of applying each function to each value

Example

 > List.apply [double; triple] [1; 2; 3];;  
 val it : int list = [2; 4; 6; 3; 6; 9]
Multiple items
module List from Microsoft.FSharp.Collections

--------------------
type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ...
Multiple items
val double: value: 'T -> double (requires member op_Explicit)

--------------------
type double = System.Double

--------------------
type double<'Measure> = float<'Measure>
Multiple items
val int: value: 'T -> int (requires member op_Explicit)

--------------------
type int = int32

--------------------
type int<'Measure> = int
type 'T list = List<'T>

List.choosei mapping source

Full Usage: List.choosei mapping source

Parameters:
    mapping : int -> 'b -> 'c option - The mapping function, taking index and element as parameters.
    source : 'b list - The input list.

Returns: 'c list List with values x for each List value where the function returns Some(x).

Same as choose but with access to the index.

mapping : int -> 'b -> 'c option

The mapping function, taking index and element as parameters.

source : 'b list

The input list.

Returns: 'c list

List with values x for each List value where the function returns Some(x).

List.cons value list

Full Usage: List.cons value list

Parameters:
    value : 'T - The element to add
    list : 'T list - The list to add to

Returns: 'T list A concatenated list of the result lists of applying each function to each value

Adds an element to the beginning of the given list

Note: this function has since been added to FSharp.Core. It will be removed in next major release of FSharpPlus.

value : 'T

The element to add

list : 'T list

The list to add to

Returns: 'T list

A concatenated list of the result lists of applying each function to each value

List.deleteAt i lst

Full Usage: List.deleteAt i lst

Parameters:
    i : int - The index of the item to remove
    lst : 'd list - The input list

Returns: 'd list For invalid indexes, the input list. Otherwise, a new list with the item removed.

Attempts to remove an item from a list.

Use List.removeAt from FSharp.Core if you want to throw exceptions when using invalid indexes.

i : int

The index of the item to remove

lst : 'd list

The input list

Returns: 'd list

For invalid indexes, the input list. Otherwise, a new list with the item removed.

List.drop count source

Full Usage: List.drop count source

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

Returns: 'T list The result list.

Returns a list that drops N elements of the original list and then yields the remaining elements of the list.

When count exceeds the number of elements in the list it returns an empty list instead of throwing an exception.

count : int

The number of items to drop.

source : 'T list

The input list.

Returns: 'T list

The result list.

List.findSliceIndex slice source

Full Usage: List.findSliceIndex slice source

Parameters:
    slice : 'b list
    source : 'b list

Returns: int The index of the slice.

Gets the index of the first occurrence of the specified slice in the source.

slice : 'b list
source : 'b list
Returns: int

The index of the slice.

ArgumentException Thrown when the slice was not found in the sequence.

List.intercalate separator source

Full Usage: List.intercalate separator source

Parameters:
    separator : 'T list
    source : seq<'T list>

Returns: 'T list

Concatenates all elements, using the specified separator between each element.

separator : 'T list
source : seq<'T list>
Returns: 'T list

List.intersperse separator source

Full Usage: List.intersperse separator source

Parameters:
    separator : 'T
    source : 'T list

Returns: 'T list

Inserts a separator element between each element in the source list.

separator : 'T
source : 'T list
Returns: 'T list

List.lift2 f x1 x2

Full Usage: List.lift2 f x1 x2

Parameters:
    f : 'T1 -> 'T2 -> 'U
    x1 : 'T1 list
    x2 : 'T2 list

Returns: 'U list

Combines all values from the first list with the second, using the supplied mapping function.

f : 'T1 -> 'T2 -> 'U
x1 : 'T1 list
x2 : 'T2 list
Returns: 'U list

List.lift3 f x1 x2 x3

Full Usage: List.lift3 f x1 x2 x3

Parameters:
    f : 'e -> 'f -> 'g -> 'h - Mapping function taking three element combination as input.
    x1 : 'g list - First list.
    x2 : 'e list - Second list.
    x3 : 'f list - Third list.

Returns: 'h list List with values returned from mapping function.

Combines values from three list and calls a mapping function on this combination.

f : 'e -> 'f -> 'g -> 'h

Mapping function taking three element combination as input.

x1 : 'g list

First list.

x2 : 'e list

Second list.

x3 : 'f list

Third list.

Returns: 'h list

List with values returned from mapping function.

List.map2Shortest mapping list1 list2

Full Usage: List.map2Shortest mapping list1 list2

Parameters:
    mapping : 'T1 -> 'T2 -> 'U - Mapping function.
    list1 : 'T1 list - First input list.
    list2 : 'T2 list - Second input list.

Returns: 'U list List with corresponding results of applying the mapping function pairwise over both input lists elments.

Safely build a new list whose elements are the results of applying the given function to each of the elements of the two lists pairwise.

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

Mapping function.

list1 : 'T1 list

First input list.

list2 : 'T2 list

Second input list.

Returns: 'U list

List with corresponding results of applying the mapping function pairwise over both input lists elments.

List.partitionMap mapping source

Full Usage: List.partitionMap mapping source

Parameters:
    mapping : 'T -> Choice<'T1, 'T2>
    source : 'T list

Returns: 'T1 list * 'T2 list A tuple with both resulting lists.

Creates two lists by applying the mapping function to each element in the list and classifying the transformed values depending on whether they were wrapped with Choice1Of2 or Choice2Of2.

mapping : 'T -> Choice<'T1, 'T2>
source : 'T list
Returns: 'T1 list * 'T2 list

A tuple with both resulting lists.

List.replace oldValue newValue source

Full Usage: List.replace oldValue newValue source

Parameters:
    oldValue : seq<'T>
    newValue : 'T list
    source : 'T list

Returns: 'T list

Replaces a subsequence of the source list with the given replacement list.

oldValue : seq<'T>
newValue : 'T list
source : 'T list
Returns: 'T list

List.setAt i x lst

Full Usage: List.setAt i x lst

Parameters:
    i : int - The index of the item to update
    x : 'd - The new value of the item
    lst : 'd list - The input list

Returns: 'd list A new list with the updated element

Updates the value of an item in a list

Use List.updateAt from FSharp.Core if you want to throw exceptions when using invalid indexes.

i : int

The index of the item to update

x : 'd

The new value of the item

lst : 'd list

The input list

Returns: 'd list

A new list with the updated element

List.singleton value

Full Usage: List.singleton value

Parameters:
    value : 'T - The input item.

Returns: 'T list The result list of one item.

Returns a list that contains one item only.

Note: this function has since been added to FSharp.Core. It will be removed in next major release of FSharpPlus.

value : 'T

The input item.

Returns: 'T list

The result list of one item.

Example

 List.singleton 7
Multiple items
module List from Microsoft.FSharp.Collections

--------------------
type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ...
val singleton: value: 'T -> 'T list
Evaluates to [ 7 ].

List.skip count list

Full Usage: List.skip count list

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

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

Returns the list after removing the first N elements.

Note: this function has since been added to FSharp.Core. It will be removed in next major release of FSharpPlus.

count : int

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

list : 'T list

The input list.

Returns: 'T list

The list after removing the first N elements.

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

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

 inputs |> List.skip 2
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections

--------------------
type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ...
val skip: count: int -> list: 'T list -> 'T list
Evaluates to ["c"; "d"]

Example

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

 inputs |> List.skip 5
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections

--------------------
type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ...
val skip: count: int -> list: 'T list -> 'T list
Throws ArgumentException.

Example

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

 inputs |> List.skip -1
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections

--------------------
type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ...
val skip: count: int -> list: 'T list -> 'T list
Evaluates to ["a"; "b"; "c"; "d"].

List.split separators source

Full Usage: List.split separators source

Parameters:
    separators : seq<'a list>
    source : 'a list

Returns: seq<'a list>

Creates a sequence of lists by splitting the source list on any of the given separators.

separators : seq<'a list>
source : 'a list
Returns: seq<'a list>

List.tails list

Full Usage: List.tails list

Parameters:
    list : 'T list

Returns: 'T list list

Returns a list with all possible tails of the source list.

list : 'T list
Returns: 'T list list

List.take count list

Full Usage: List.take count list

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

Returns: 'T list The result list.

Returns the first N elements of the list.

Throws InvalidOperationException if the count exceeds the number of elements in the list. List.truncate returns as many items as the list contains instead of throwing an exception. Note: this function has since been added to FSharp.Core. It will be removed in next major release of FSharpPlus.

count : int

The number of items to take.

list : 'T list

The input list.

Returns: 'T list

The result list.

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

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

 inputs |> List.take 2
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections

--------------------
type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ...
val take: count: int -> list: 'T list -> 'T list
Evaluates to ["a"; "b"]

Example

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

 inputs |> List.take 6
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections

--------------------
type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ...
val take: count: int -> list: 'T list -> 'T list
Throws InvalidOperationException.

Example

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

 inputs |> List.take 0
val inputs: string list
Multiple items
module List from Microsoft.FSharp.Collections

--------------------
type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ...
val take: count: int -> list: 'T list -> 'T list
Evaluates to the empty list.

List.toIReadOnlyList source

Full Usage: List.toIReadOnlyList source

Parameters:
    source : 'a list - The list source

Returns: IReadOnlyList<'a> The list converted to a System.Collections.Generic.IReadOnlyList

Converts a list to an IReadOnlyList (from System.Collections.Generic).

source : 'a list

The list source

Returns: IReadOnlyList<'a>

The list converted to a System.Collections.Generic.IReadOnlyList

List.tryFindSliceIndex slice source

Full Usage: List.tryFindSliceIndex slice source

Parameters:
    slice : 'b list
    source : 'b list

Returns: int option The index of the slice or None.

Gets the index of the first occurrence of the specified slice in the source. Returns None if not found.

slice : 'b list
source : 'b list
Returns: int option

The index of the slice or None.

List.zipShortest list1 list2

Full Usage: List.zipShortest list1 list2

Parameters:
    list1 : 'T1 list - First input list.
    list2 : 'T2 list - Second input list.

Returns: ('T1 * 'T2) list List with corresponding pairs of input lists.

Zip safely two lists. If one list is shorter, excess elements are discarded from the right end of the longer list.

list1 : 'T1 list

First input list.

list2 : 'T2 list

Second input list.

Returns: ('T1 * 'T2) list

List with corresponding pairs of input lists.