Creating list ranges in F#

We can easily create a list of integers in F# with a start and end value as follows:

let myRangeList = [1..10]

myRangeList will contain the integers from 1 to 10:

int list = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10]

We can also add a step parameter in the middle to increment the values by some number:

let myRangeList = [1..3..10]

myRangeList will contain the values [1; 4; 7; 10].

If the step variable is 2 then the last element in the list will be 9 since 11 is more than the top value 10:

let myRangeList = [1..2..10]

int list = [1; 3; 5; 7; 9]

We can also create a list of floats:

let myFloatList = [2. ..0.3 .. 8.]

myFloatList will contain the following elements:

float list =
[2.0; 2.3; 2.6; 2.9; 3.2; 3.5; 3.8; 4.1; 4.4; 4.7; 5.0; 5.3; 5.6; 5.9; 6.2;
6.5; 6.8; 7.1; 7.4; 7.7; 8.0]

View all F# related articles here.

Advertisements

About Andras Nemes
I'm a .NET/Java developer living and working in Stockholm, Sweden.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

ultimatemindsettoday

A great WordPress.com site

Elliot Balynn's Blog

A directory of wonderful thoughts

Robin Sedlaczek's Blog

Developer on Microsoft Technologies

HarsH ReaLiTy

A Good Blog is Hard to Find

Softwarearchitektur in der Praxis

Wissenswertes zu Webentwicklung, Domain-Driven Design und Microservices

the software architecture

thoughts, ideas, diagrams,enterprise code, design pattern , solution designs

Technology Talks

on Microsoft technologies, Web, Android and others

Software Engineering

Web development

Disparate Opinions

Various tidbits

chsakell's Blog

Anything around ASP.NET MVC,WEB API, WCF, Entity Framework & AngularJS

Cyber Matters

Bite-size insight on Cyber Security for the not too technical.

Guru N Guns's

OneSolution To dOTnET.

Johnny Zraiby

Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

%d bloggers like this: