次の方法で共有


Collections.List Module (F#)

Basic operations on lists.

Namespace/Module Path: Microsoft.FSharp.Collections

Assembly: FSharp.Core (in FSharp.Core.dll)

module List

Remarks

For an overview of lists in F#, see Lists (F#).

Values

Value

Description

append : 'T list -> 'T list -> 'T list

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

average : 'T list -> ^T

Returns the average of the elements in the list.

averageBy : ('T -> ^U) -> 'T list -> ^U

Returns the average of the elements generated by applying the function to each element of the list.

choose : ('T -> 'U option) -> 'T list -> 'U list

Applies the given function to each element of the list. Returns the list comprised of the results for each element where the function returns Some.

collect : ('T -> 'U list) -> 'T list -> 'U list

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

concat : seq<'T list> -> 'T list

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

empty : 'T list

Returns an empty list of the given type.

exists : ('T -> bool) -> 'T list -> bool

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

exists2 : ('T1 -> 'T2 -> bool) -> 'T1 list -> 'T2 list -> bool

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

filter : ('T -> bool) -> 'T list -> 'T list

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

find : ('T -> bool) -> 'T list -> 'T

Returns the first element for which the given function returns true.

findIndex : ('T -> bool) -> 'T list -> int

Returns the index of the first element in the list that satisfies the given predicate.

fold : ('State -> 'T -> 'State) -> 'State -> 'T list -> 'State

Applies a function to each element of the collection, threading an accumulator argument through the computation. This function takes the second argument, and applies the function to it and the first element of the list. Then, it passes this result into the function along with the second element, and so on. Finally, it returns the final result. If the input function is f and the elements are i0...iN, then this function computes f (... (f s i0) i1 ...) iN.

fold2 : ('State -> 'T1 -> 'T2 -> 'State) -> 'State -> 'T1 list -> 'T2 list -> 'State

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 this function computes f (... (f s i0 j0)...) iN jN.

foldBack : ('T -> 'State -> 'State) -> 'T list -> 'State -> 'State

Applies a function to each element of the collection, 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)).

foldBack2 : ('T1 -> 'T2 -> 'State -> 'State) -> 'T1 list -> 'T2 list -> 'State -> 'State

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 this function computes f i0 j0 (...(f iN jN s)).

forall : ('T -> bool) -> 'T list -> bool

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

forall2 : ('T1 -> 'T2 -> bool) -> 'T1 list -> 'T2 list -> bool

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

head: 'T list -> 'T

Returns the first element of the list.

init : int -> (int -> 'T) -> 'T list

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

isEmpty : 'T list -> bool

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

iter : ('T -> unit) -> 'T list -> unit

Applies the given function to each element of the collection.

iter2 : ('T1 -> 'T2 -> unit) -> 'T1 list -> 'T2 list -> unit

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

iteri : (int -> 'T -> unit) -> 'T list -> unit

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

iteri2 : (int -> 'T1 -> 'T2 -> unit) -> 'T1 list -> 'T2 list -> unit

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

length : 'T list -> int

Returns the length of the list.

map : ('T -> 'U) -> 'T list -> 'U list

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

map2 : ('T1 -> 'T2 -> 'U) -> 'T1 list -> 'T2 list -> 'U list

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

map3 : ('T1 -> 'T2 -> 'T3 -> 'U) -> 'T1 list -> 'T2 list -> 'T3 list -> 'U list

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

mapi : (int -> 'T -> 'U) -> 'T list -> 'U list

Creates 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 element being transformed.

mapi2 : (int -> 'T1 -> 'T2 -> 'U) -> 'T1 list -> 'T2 list -> 'U list

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

max : 'T list -> 'T

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

maxBy : ('T -> 'U) -> 'T list -> 'T

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

min : 'T list -> 'T

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

minBy : ('T -> 'U) -> 'T list -> 'T

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

nth : 'T list -> int -> 'T

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

ofArray : 'T [] -> 'T list

Creates a list from the given array.

ofSeq : seq<'T> -> 'T list

Creates a new list from the given enumerable object.

partition : ('T -> bool) -> 'T list * 'T list

Splits the collection into two collections, containing the elements for which the given predicate returns true and false respectively.

permute : (int -> int) -> 'T list -> 'T list

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

pick : ('T -> 'U option) -> 'T list -> 'U

Applies the given function to successive elements, returning the first result where function returns Some for some value.

reduce : ('T -> 'T -> 'T) -> 'T list -> 'T

Applies a function to each element of the collection, threading an accumulator argument through the computation. This function applies the specified function to the first two elements of the list. It then passes this result into the function along with the third element, and so on. Finally, it returns the final result. If the input function is f and the elements are i0...iN, then this function computes f (... (f i0 i1) i2 ...) iN.

reduceBack : ('T -> 'T -> 'T) -> 'T list -> 'T

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

replicate : (int -> 'T -> 'T list)

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

rev : 'T list -> 'T list

Returns a new list with the elements in reverse order.

scan : ('State -> 'T -> 'State) -> 'State -> 'T list -> 'State list

Applies a function to each element of the collection, threading an accumulator argument through the computation. This function takes the second argument, and applies the specified function to it and the first element of the list. Then, it passes this result into the function along with the second element and so on. Finally, it returns the list of intermediate results and the final result.

scanBack : ('T -> 'State -> 'State) -> 'T list -> 'State -> 'State list

Like foldBack, but returns both the intermediate and final results

sort : 'T list -> 'T list

Sorts the given list using Operators.compare.

sortBy : ('T -> 'Key) -> 'T list -> 'T list

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

sortWith : ('T -> 'T -> int) -> 'T list -> 'T list

Sorts the given list using the given comparison function.

sum : ^T list -> ^T

Returns the sum of the elements in the list.

sumBy : ('T -> ^U) -> 'T list -> ^U

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

tail : 'T list -> 'T list

Returns the input list without the first element.

toArray : 'T list -> 'T []

Creates an array from the given list.

toSeq : 'T list -> seq<'T>

Views the given list as a sequence.

tryFind : ('T -> bool) -> 'T list -> 'T option

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

tryFindIndex : ('T -> bool) -> 'T list -> int option

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

tryPick : ('T -> 'U option) -> 'T list -> 'U option

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

unzip : ('T1 * 'T2) list -> 'T1 list * 'T2 list

Splits a list of pairs into two lists.

unzip3 : ('T1 * 'T2 * 'T3) list -> 'T1 list * 'T2 list * 'T3 list

Splits a list of triples into three lists.

zip : 'T1 list -> 'T2 list -> ('T1 * 'T2) list

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

zip3 : 'T1 list -> 'T2 list -> 'T3 list -> ('T1 * 'T2 * 'T3) list

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

Platforms

Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

Version Information

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

See Also

Reference

Microsoft.FSharp.Collections Namespace (F#)

Other Resources

Lists (F#)