This post is targeting developers starting with F Sharp. Level: 100
We can find the square of a range of numbers in F# using List.Map
If you have range of numbers from 1 to 10 declared as below,
List.Map takes two parameters. It takes a mapping and the list.
If you print squreNumbers you should get an output of the square of the numbers from 1 to
10.
Full code is as below,
let number = [1..10]
let squre x= x*x
let squreNumbers = List.map squre number
printfn "SqureNubers = %A" squreNumbers
open System
printfn "Press any key to continue"
Console.ReadKey(true);
Press F5 to get the output,
I hope this post was useful. Thanks for reading.
If you find my posts useful you may like to follow me on twitter http://twitter.com/debug_mode
or may like Facebook page of my blog http://www.facebook.com/DebugMode.Net If
you want to see post on a particular topic please do write on FB page or tweet
me about that, I would love to help you.