Javatpoint Logo
Javatpoint Logo

F# Sequence

In F#, sequence is a series of same type of elements. It provides better performance than list.

It is useful when you have large ordered collection of data but don't want to use all the elements.

Syntax:

You can create sequence by specifying start and end index. You can also create by adding skip element between start and end index. Let's see an example.


F# Creating Sequence Expression Example1

You can create sequence expression like following. Here, we have used Seq.iter () function to iterate sequence. we can also use for loop or array format specifier to iterate sequence elements.

Output:

0 1 2 3 4 5 6 7 8 9 10

F# Creating Sequence Example2

You can also create sequence by adding a skip element between the start and end index.

Output:

0 5 10 15 20 25 30 35 40 45 50

F# Creating Sequence from Array Example

You can also create sequence from array by using ofArray method. Let's see an example.

Output:

1 2 3 4 5 6 7 8 9 10

F# Creating Sequence from List Example

You can create sequence by using ofList method also.

Output:

1 2 3 4 5 6 7 8 9 10

F# Searching Element in Sequence

In Sequence, Seq.exists() method searches for the element. It returns true if element found otherwise returns false. Let's see an example.

Output:

false

F# Sorting Sequence Example

In Sequence, Seq.sort() method is used to sort element in the sequence. Let's see an example.

Output:

2 3 4 5 8 
Next TopicF# Options





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA